find string and get the rest of the line in a pipe delimited file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers find string and get the rest of the line in a pipe delimited file
# 8  
Old 02-15-2012
Quote:
Originally Posted by balajesuri
Code:
#! /bin/bash
while read x
do
    mapped=`grep $x output`
    echo ${mapped#*|}
done < input_string.txt

i think this works with the premise.
# 9  
Old 02-16-2012
If the awk version works, that will be much faster.

If it doesn't, please describe how. I've done the best I can with an incomplete description.
# 10  
Old 02-16-2012
Quote:
Originally Posted by Corona688
If the awk version works, that will be much faster.

If it doesn't, please describe how. I've done the best I can with an incomplete description.
Sorry for the confusion. I can't figure out how to use you awk with the restriction of the while loop in my premise. The output file that I need to generate requires other information from other calculations. So extracting the mapped number at once will not work since I need to work on it line by line. Thanks Smilie
# 11  
Old 02-16-2012
Quote:
Originally Posted by kokoro
Sorry for the confusion. I can't figure out how to use you awk with the restriction of the while loop in my premise. The output file that I need to generate requires other information from other calculations. So extracting the mapped number at once will not work since I need to work on it line by line. Thanks Smilie
You can pipe awk into the entire loop.

Code:
awk ... | while read LINE
do
        echo $LINE
done

# 12  
Old 02-17-2012
Hi Kokoro, I I understand you correctly then you need to find labels and values in the file mapping.txt, corresponding to the labels in the file input_strings and both files may be quite large. And subsequently you need this result in a while loop so that you can work with this in shell variables inside the loop. Give this a try:

Code:
grep -wFf input_string.txt mapping.txt |
while IFS="|" read -r label val
do
  echo "label $label has value $val"
done > outfile

The grep may have false matches if one of the values are equal to one of the labels.
An alternative to grep might be:
Code:
awk -F\| 'NR==FNR{A[$1];next}$1 in A' input_string.txt mapping.txt |

So you can feed either the grep or the awk into the loop and see which one works better.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove new line characters from data rows in a Pipe delimited file?

I have a file as below Emp1|FirstName|MiddleName|LastName|Address|Pincode|PhoneNumber 1234|FirstName1|MiddleName2|LastName3| Add1 || ADD2|123|000000000 2345|FirstName2|MiddleName3|LastName4| Add1 || ADD2| 234|000000000 OUTPUT : ... (1 Reply)
Discussion started by: styris
1 Replies

2. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

3. Shell Programming and Scripting

Replace pipe delimited column string to null

Hi All, I have a large dat file where each lines are pipe delimited values. I need to parse the file depending on the request. For example: sometimes I have told to remove all the values in the 7th column (this case remove values '3333' only from the first line and '3543' from the second line)... (4 Replies)
Discussion started by: express14
4 Replies

4. Shell Programming and Scripting

How to ignore Pipe in Pipe delimited file?

Hi guys, I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file for eg: file 1: xx|yy|"xyz|zzz"|zzz|12... using below awk command awk 'BEGIN {FS=OFS="|" } print $3 i would get xyz But i want as : xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies

5. Shell Programming and Scripting

Find for line with not null values at nth place in pipe delimited file

Hi, I am trying to find the lines in a pipe delimited file where 11th column has not null values. Any help is appreciated. Need help asap please. thanks in advance. (3 Replies)
Discussion started by: manikms
3 Replies

6. Shell Programming and Scripting

Find the text in the file and delete the rest of the line.

Hi, I have one requiremnet like this. I need to find some particular string (eg.IncludeDateTime = ) in a file. And wherever it finds the string the unix script has to delete the remaining text coming after the string (ie., 'IncludeDateTime = ' ) in the same line. I tried to write this script in... (5 Replies)
Discussion started by: jannusuresh
5 Replies

7. Shell Programming and Scripting

Help with converting Pipe delimited file to Tab Delimited

I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use cat file | sed 's/|//t/g' The above command substituted "/t" not tab in the place of pipe. Sample file: abc|123|2012-01-30|2012-04-28|xyz have to convert to: abc 123... (6 Replies)
Discussion started by: karumudi7
6 Replies

8. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

9. Shell Programming and Scripting

how to build a pipe delimited string

#! /bin/csh set delimiter = | foreach i (*) set str_deli="$i$delimiter" question: how to retain the value of str_deli so i can build a pipe delimited string? end (1 Reply)
Discussion started by: jdsignature88
1 Replies

10. Shell Programming and Scripting

convert a pipe delimited file to a':" delimited file

i have a file whose data is like this:: osr_pe_assign|-120|wg000d@att.com|4| osr_evt|-21|wg000d@att.com|4| pe_avail|-21|wg000d@att.com|4| osr_svt|-11|wg000d@att.com|4| pe_mop|-13|wg000d@att.com|4| instar_ready|-35|wg000d@att.com|4| nsdnet_ready|-90|wg000d@att.com|4|... (6 Replies)
Discussion started by: priyanka3006
6 Replies
Login or Register to Ask a Question