Place digit in front of the line searching pattern using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Place digit in front of the line searching pattern using sed command
# 8  
Old 04-15-2011
Quote:
Originally Posted by krbala1985
really Thank you....can u explain the command.

another thing i need to update the output report file itself.
Code:
awk 'NR==FNR{a[$1]=$2;next} ## NR>FNR means awk is reading through the "pattern" as input, also building an array a: a[$1]=$2. "next" means then start to read "report" 
{for(i=1;i<=NF;i++) if($i in a) print a[$i] FS $0}  ## if $i exsit in the array a, print a[$i](the value is from "pattern") and $0 
' pattern report

using a temp file like
Code:
 awk code pattern report >tmp; cat tmp >report ;rm tmp

# 9  
Old 04-15-2011
Thanks ya!...

sorry for trouble again...i have wriiten one code for same thing but i am using sed command it is going to place the digit front of the pattern in the report file. but all the lines is there....

Please check my script,pattern file and sample report files and give suggestion how to place the digit front of the line.

here pattern file Name: sch.txt
Report file Names Ext: *.R

script:

for i in `ls *.R`
do
cat sch.txt | while read LINE
do
CLT=`echo $LINE | cut -f1 -d "|"`
NAME=`echo $LINE | cut -f2 -d "|"`
NUM=`echo $LINE | cut -f3 -d "|"`
echo " $NAME $NUM$NAME "
comp_string=`grep "%s" $i| cut -d ":" -f2 | cut -d "|" -f1`
if [ $CLT = $comp_string ]
then
NAME1=`grep $NAME $i`
cat $i | sed "s:$NAME:$NUM$NAME:g" > tmp_file.dat
cat tmp_file.dat > $i
else
echo " Not Matching CLient Code"
fi
done
done
# 10  
Old 04-15-2011
try:
Code:
for i in `ls *.R`
do
cat sch.txt | while read LINE
do
CLT=`echo $LINE | cut -f1 -d "|"`
NAME=`echo $LINE | cut -f2 -d "|"`
NUM=`echo $LINE | cut -f3 -d "|"`
echo " $NAME $NUM$NAME "
comp_string=`grep "%s" $i| cut -d ":" -f2 | cut -d "|" -f1`
if [ $CLT = $comp_string ]
then
#NAME1=`grep $NAME $i` 
sed -i "/$NAME/s/.*/$NUM &/" $i
#cat $i | sed "s:$NAME:$NUM$NAME:g" > tmp_file.dat
#cat tmp_file.dat > $i
else
echo " Not Matching CLient Code"
fi
done
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed command that deletes lines with 3-5 digit strings

Hello! My final exam in my Linux class is tomorrow, and I was just reviewing the grep and sed commands. I came across an example, by which I got stumped: it asks to provide a sed command that deletes all lines that contain exactly 3 to 5 digit strings, from a file. In this case, I created a... (3 Replies)
Discussion started by: kalpcalp
3 Replies

2. Shell Programming and Scripting

awk pattern matching in place of sed

I have written a script to parse data from some files on a Solaris 10 system and send the output to a CSV formatted file. The code snipped i am using to pull the data is as follows.... src_line=$(sed -n "/^search_pattern$/{=;}" $file) for i in $src_line do start_line1=$(( i + 9 )) nawk -v... (4 Replies)
Discussion started by: electricheadx
4 Replies

3. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

problem using pattern with two digit in sed

Hi, I am trying to create a csv from a existing flat file.I am using the same data to create the csv file. But I have issues \10 columns onwards.. sed... (5 Replies)
Discussion started by: babom
5 Replies

5. Shell Programming and Scripting

how to add single digit in front of the word and line in the file.

Hi , how to add the single digit to front of the word and front of the lines in the one file with compare pattern file and get digit. like example pattern file pattern.txt pattern num bala 2 raja 3 muthu 4 File Name: chennai.dat muthu is good boy raja is bad boy selvam in super... (6 Replies)
Discussion started by: krbala1985
6 Replies

6. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

7. Shell Programming and Scripting

Need help in sed command [ printing a pattern + its line no or line no alone ]

Hello friends, Only very recently i started learning sed command...an i found that sed is faster in finding the patterns than some of my scripts that uses grep to check the patten inside a file using line by line search method which is time consuming. The below script... (4 Replies)
Discussion started by: frozensmilz
4 Replies

8. Shell Programming and Scripting

Sed - Pattern Searching

Hi, Please take a look at the below eg. I would like to search for abc() pattern first and then search for (xyz) in the next line. If I can find the pattern, then I should delete the 3 lines. I can only find the pattern and delete but I am unable to find two patterns and delete. Any... (8 Replies)
Discussion started by: sreedevi
8 Replies

9. Shell Programming and Scripting

Need help in sed command (adding a blank line btw each block generated by pattern)

Hello friends, I have a C source code containing sql statements. I use the following sed command to print all the sql blocks in the source code.... sed -n "/exec sql/,/;/p" Sample.cpp The above sed command will print the sql blocks based on the pattern "exec sql" & ";"... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. UNIX for Dummies Questions & Answers

How to use cat command in sed pattern searching

Hi All, I have a file named pattern.dat which contains pattern like A1000090 250.00 250.00 i have one more file named test.dat in which this pattern is present. What i should do is, in test.dat after this pattern i should append comments. i used... (4 Replies)
Discussion started by: Sona
4 Replies
Login or Register to Ask a Question