If you're going to use two greps, with the fixed strings needed for this project, grep -F (or fgrep) will be faster than egrep (or grep -E). I.e., try:
If you don't want to do this just with shell built-ins as MadeInGermany suggested, you could also use either of the following awk scripts (that just need one invocation of awk):
Note, however, that with the supplied sample data from post #1 in file1.txt, none of the above produce any output.
All of these (and the sample code shown in post #1 are looking for setting application , but the desired lines in that sample data have applicaction instead of application
To get the output requested in post #1 from the input provided in post #1, you would need to use one of the following:
This User Gave Thanks to Don Cragun For This Post:
I just want to know , is it possible to add column to the end of each record with the filename like below?
If you are reading a file line-by-line as suggested by MadeInGermany in post #2, please never feed those lines through a three element pipeline. Doing so is GROSSLY inefficient!
If you are processing multiple files (which would be a logical reason for adding the name of the file each record came from in the output you produce), you can easily modify MadeInGermany's shell suggestion from post #2 with something like:
(which just uses shell built-ins and doesn't need to invoke any external utilities) or extend my awk suggestion from post #3 to something like:
(which just invokes awk once). Note the comma between $0 and FILENAME in the print statement; without it, there won't be any separation between the input lines and the name of the file from which it was extracted.
The code that you showed us in post #4 invokes two copies of grep and one copy of awk for every line read from each of the files you process.
Hi,
I tried filtering the records in a csv file using "awk" command listed below.
awk -F"~" '$4 ~ /Active/{print }' inputfile > outputfile
The output always has all the entries.
The same command worked for different users from one of the forum links.
content of file I was... (3 Replies)
Hi I am new to shell programming in unix
Please if I can provide help.
I have a file structure of a header record and "N" detail records.
The header record will be the total number of detail records
I need to split the file in 2:
One for the header
Another for all detail records
Could... (1 Reply)
I have 2 files
"File 1" is delimited by ";" and "File 2" is delimited by "|".
File 1 below (3 record shown):
Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones
Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull
Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Hi,
I am looking for an awk script which should help me to meet the following requirement:
File1 has records in following format
INF: FAILEd RECORD AB1234
INF: FAILEd RECORD PQ1145
INF: FAILEd RECORD AB3215
INF: FAILEd RECORD AB6114
............................ (2 Replies)
Hi everyone.
I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this:
ID: 20
Name: X
Age: 19
ID: 21
Name: Z
ID: 22
Email: xxx@yahoo.com
Name: Y
Age: 19
I want to grep records that... (4 Replies)
I have a ";" delimited file.Whcih conatins a number fileds of length 4 charcters in 8th position
But there is a alphanumeric charcters like :
space, ";" , "," , "/" , "23-1" ,
"23 1" , "aqjhdj" , "jun-23" , "APR-04" , "4:00AM" , "-234" , "56784 ", "." , "+"
"_" , "&" , "*" , "^" , "%" , "!"... (2 Replies)
Hi All,
I have huge trade file with milions of trades.I need to remove duplicate records (e.g I have following records)
30/10/2009,trdeId1,..,..
26/10/2009.tradeId1,..,..,,
30/10/2009,tradeId2,..
In the above case i need to filter duplicate recods and I should get following output.... (2 Replies)
Hi all,
I would like to extract records of a file based on a condition. The file contains 47 fields, and I would like to extract only those records that match a certain value in one of the columns, e.g.
COL1 COL2 COL3 ............... COL47
1 XX 45 ... (4 Replies)
I have a flat file and need to count no of records in the file less the header and the trailer record.
I would appreciate any and all asistance
Thanks
Hadi Lalani (2 Replies)