how to find the column number in a text file using unix commands

user3622752

Suppose I have a text file with 6 columns as below

a|b|c|d|e|f

I know that somwhere in the file the character 'd' exist, but I want to know the column no for it

I have used the following command

awk 's=index($0,"d"){print "position="s}' filename

but it counts the delimiters too which I dont want....I want the output to be 4 in case of "d"

yejinxin

define "|" as Record Seperator, and use NR variable in awk:

awk -v RS="|" '/^d$/{print NR;}' filename

change ^d$ to whatever you want to match.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert a text file to binary file using linux commands

From Dev

how to count the total number of lines in a text file using python

From Dev

How to replace a column in a text file using a list?

From Dev

How to find the smallest number in a text file (Python 2.5)

From Dev

How to execute the Unix commands saved in text file on putty using batch file

From Dev

How to find number of lines in text file using python?

From Dev

How to find the number of uppercase words in a text, using ubuntu grep?

From Dev

Find different records between two files using Unix Commands

From Dev

Unix find line number of a string in a file using awk/grip

From Dev

Find Duplicates in a column with large number (as text)

From Dev

Find and replace text within a file using commands

From Dev

Original Unix Box Number of Commands

From Dev

Find the most frequent entry in a file using unix

From Dev

Find and replace text within a file using commands

From Dev

Parsing complex text file using Unix commands

From Dev

How to execute the Unix commands saved in text file on putty using batch file

From Dev

How to find number of lines in text file using python?

From Dev

Find different records between two files using Unix Commands

From Dev

How to find lines using patterns in a file in UNIX

From Dev

How to print the base file name using find in Unix?

From Dev

How to find a file in Unix using find command?

From Dev

How to find rows in a file with same values for specific columns using unix commands?

From Dev

how insert column of same number in text file?

From Dev

Reverse lines in a file using simple unix commands?

From Dev

How to find null value in file using Unix cmd

From Dev

Parsing a file using unix commands

From Dev

Find line and column number in the text file using perl

From Dev

how do I find the smallest number in a text file? (Java)

From Dev

Unix File Protection Commands

Related Related

  1. 1

    How to convert a text file to binary file using linux commands

  2. 2

    how to count the total number of lines in a text file using python

  3. 3

    How to replace a column in a text file using a list?

  4. 4

    How to find the smallest number in a text file (Python 2.5)

  5. 5

    How to execute the Unix commands saved in text file on putty using batch file

  6. 6

    How to find number of lines in text file using python?

  7. 7

    How to find the number of uppercase words in a text, using ubuntu grep?

  8. 8

    Find different records between two files using Unix Commands

  9. 9

    Unix find line number of a string in a file using awk/grip

  10. 10

    Find Duplicates in a column with large number (as text)

  11. 11

    Find and replace text within a file using commands

  12. 12

    Original Unix Box Number of Commands

  13. 13

    Find the most frequent entry in a file using unix

  14. 14

    Find and replace text within a file using commands

  15. 15

    Parsing complex text file using Unix commands

  16. 16

    How to execute the Unix commands saved in text file on putty using batch file

  17. 17

    How to find number of lines in text file using python?

  18. 18

    Find different records between two files using Unix Commands

  19. 19

    How to find lines using patterns in a file in UNIX

  20. 20

    How to print the base file name using find in Unix?

  21. 21

    How to find a file in Unix using find command?

  22. 22

    How to find rows in a file with same values for specific columns using unix commands?

  23. 23

    how insert column of same number in text file?

  24. 24

    Reverse lines in a file using simple unix commands?

  25. 25

    How to find null value in file using Unix cmd

  26. 26

    Parsing a file using unix commands

  27. 27

    Find line and column number in the text file using perl

  28. 28

    how do I find the smallest number in a text file? (Java)

  29. 29

    Unix File Protection Commands

HotTag

Archive