Find a string and then return the next 20 characters in multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find a string and then return the next 20 characters in multiple files
# 8  
Old 09-25-2013
wonderful, it works perfectly!!!
# 9  
Old 09-25-2013
You may want to know the filename attached to that invoice number, and the invoice number may be less than, or even more than 8 chars. Try this:
Code:
awk '{for (i=1;  i<=NF; i++) if ($i=="BIG") print FILENAME, ": ", $i, $(i+1), $(i+2)}' FS="|"  *
file :  BIG 20130924 49685234

In case there's only one InvNo per file, and your awk has the "nextfile" command, you may want to add the nextfile to the end of the script line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Scripting | Return list of unique characters in files

Hi, I am trying to script the below, but I am not very good at it :( Your help would be greatly appreciated. 1. read all files in the directory in strings strings *.* 2. in each file, for each line that contains "ABCD", store characters located at position 521 and 522 of this line... (9 Replies)
Discussion started by: clippertm
9 Replies

2. UNIX for Dummies Questions & Answers

insert multiple characters in string

Hello, newb here :o How do I add square brackets before and after the first character in a string using sed? e.g. 0123456 123456 My attempts have been fruitless. sed 's/.\{0\}//' Thanks. (2 Replies)
Discussion started by: shadyuk
2 Replies

3. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

4. Shell Programming and Scripting

Help to find string and return following characters from list of files

Hi, I'm fairly new to UNIX, but hopefully some-one can help me with this: I am using the following code to find files with the name "example.xml": find . -name "example.xml" -print that would print me a list like the example here: ./dir1/dir2/example.xml... (5 Replies)
Discussion started by: boijie
5 Replies

5. Shell Programming and Scripting

How to find particular string in multiple files

Hello friends, I have find a paticular string from the files present in my user for example: a username and password is hardcoded in multiple files which present in the my user.so I have to search about username in which files it is available.there are several dirctories are there,so... (5 Replies)
Discussion started by: sivaranga001
5 Replies

6. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

7. Shell Programming and Scripting

find string from multiple dir and redirect to new files

Hi, I am new to script and I want find one string from multiple files in diff directories and put that out put to new file. Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt Now I want write script to find the string... (8 Replies)
Discussion started by: Mahessh123
8 Replies

8. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

9. Shell Programming and Scripting

Script to find string and return next 2 lines

I am trying to create a script to search for a string within a file, and if found, return the next two lines. Example file:- msj mh query return this 1 return this 2 mjk mhj query return this 3 return this 4 So the script would identify the string "query" and then return the lines... (10 Replies)
Discussion started by: daveaasmith
10 Replies

10. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies
Login or Register to Ask a Question