Req 1-liner for Awk, et al to find str position


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Req 1-liner for Awk, et al to find str position
# 1  
Old 07-12-2010
Req 1-liner for Awk, et al to find str position

Hi, I'm trying to find the position of a series of numbers within a large text file. The numbers are separated by spaces.

This works fine:

Code:
type Huge_File.txt | gawk "{print index($0,"255")}"

But this does not:

Code:
type Huge_File.txt | gawk "{print index($0,"188 028 239 160 016 190 137 063")}"

I get this error:
Code:
gawk: cmd. line:2:                    ^ unexpected newline
The process tried to write to a nonexistent pipe.

I'm looking for very specific numbers, so no regex needed. What's the proper incantation for a series of numbers?

Gawk is being called by another script, which is why I'm looking for a 1-liner.

I'm using GNU utilities for Win32, and I'm on Vista. The double-quotes are correct for Windows. Also, I have no particular preference for Awk and can use any other Unix util like Grep, Sed, Tr or whatever.

Thanks,
Lemming.

Last edited by pludi; 07-12-2010 at 09:33 AM.. Reason: code tags, please...
# 2  
Old 07-12-2010
Have you tried:
Code:
type Huge_File.txt | gawk '{print index($0,"188 028 239 160 016 190 137 063")}'

# 3  
Old 07-12-2010
Yeah, that's the first thing I tried. All I get is this:

Code:
gawk: cmd. line:1: '{print
gawk: cmd. line:1: ^ invalid char ''' in expression

Seems to be a Win32 thing; you need to use double-quotes for this version.
# 4  
Old 07-12-2010
Code:
c:\>type Huge_File.txt | gawk "{print index($0,\"188 028 239 160 016 190 137 063\")}"

This User Gave Thanks to kurumi For This Post:
# 5  
Old 07-13-2010
backslash double quotes

Hi kurumi, that works great.

Thanks!

Quote:
Originally Posted by kurumi
Code:
c:\>type Huge_File.txt | gawk "{print index($0,\"188 028 239 160 016 190 137 063\")}"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Find position of character with awk

Hi Guys! Could anyone help me with?.. I have a line which says BCVGF%6$#900 .....How can we know which position is for % or say $ by command or script?There is any way to get a prompt by any script? Thanks a lot (6 Replies)
Discussion started by: Indra2011
6 Replies

2. Red Hat

find . -name '*.req' -mtime +2 -exec rm {} \; not deleting files

i want to remove *.req files from directory /opt/FFCL8001/oracle/inst/apps/FFCL8001_lhrho/logs/appl/conc/log i executed command find . -name '*.req' -mtime +2 -exec rm {} \; but it is running since hours and free space in /opt is same as old 7.4 GB . why it is not removing files ? (5 Replies)
Discussion started by: rehantayyab82
5 Replies

3. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

4. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

5. Shell Programming and Scripting

Remove text from n position to n position sed/awk

I want to remove text from nth position to nth position couple of times in same line my line is "hello is there anyone can help me with this question" I need like this ello is there anyone can help me with question 'h' is removed and 'this' removed from the line. I want to do this... (5 Replies)
Discussion started by: elamurugu
5 Replies

6. Shell Programming and Scripting

Held req: Awk - remove non-alpha line

Hi All, I have a file containg lines along the likes of: 18:02:00 JOB02084722 18:09:00 2010120942 18:12:04 JOB02084723 18:34:16 20100709 etc. What I want to do is remove the entire line when field 2 starts with a number so I'm left with: 18:02:00 JOB02084722 18:12:04... (8 Replies)
Discussion started by: Grueben
8 Replies

7. UNIX for Dummies Questions & Answers

awk one liner

I need a one liner to" find /pattern/ print from x lines before "pattern" to y lines after "pattern" (3 Replies)
Discussion started by: kenneth.mcbride
3 Replies

8. UNIX for Dummies Questions & Answers

find if a position is between a given start and end position

Hi, I am a newbie in unix programming so maybe this is a simple question. I would like to know how can I make a script that outputs only the values that are not between any given start and end positions Example file1: 2 30 40 80 82 100 file2: ID1 1 ID2 35 ID3 80 ID4 81 ID6... (9 Replies)
Discussion started by: fadista
9 Replies

9. Shell Programming and Scripting

how to find a position and print some string in the next and same position

I need a script for... how to find a position of column data and print some string in the next line and same position position should find based on *HEADER8* in text for ex: ord123 abs 123 987HEADER89 test234 ord124 abc 124 987HEADER88 test235 ... (1 Reply)
Discussion started by: naveenkcl
1 Replies

10. Shell Programming and Scripting

(Req)Shell script req

HI All Im new to shell scripting...kindly plz help me... I need a shell script for: We have to take export of all db's on daily basis from all svr's and keep these export backups on diffrent server. Plz help. Regards Gaurav (5 Replies)
Discussion started by: ergauravtaneja
5 Replies
Login or Register to Ask a Question