Shell Script for displaying the line till the target word


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell Script for displaying the line till the target word
# 8  
Old 07-20-2013
Show us the KSH script that you created.
# 9  
Old 07-20-2013
Hi my code:

Code:
PATTERN_FILE=File.txt

### read pattern from file
exec 5<$PATTERN_FILE
 
   while read -r PATTERN <&5
   do
      x=$PATTERN" "$x 
      
   done
perl -pe 's/([^ \047]*$x)(\047,)?.*/^^^^^$1^^^^^$2/' line.txt

File.txt: t2,t3,dev
line.txt :
testingt2
devlopment


output coming as :^^^^^^^testingt2
^^^^^devlopment

but expected output:
testing^^^^t2^^^
^^^dev^^lopment..please help me

---------- Post updated at 05:08 AM ---------- Previous update was at 04:38 AM ----------

Hi have a doubt in the partSmilieerl -pe 's/([^ \047]*$x)
i have tried also using the $x and i have also used the below script but no use

Code:
   while read -r PATTERN <&5
   do
      x=$PATTERN" "$x 
  
     
   done
   for i in $x 
   do
   perl -pe 's/([^ \047]$x)(\047,)?.*/^^^^^$1^^^^^$2/' /final.txt 
   done

---------- Post updated at 05:14 AM ---------- Previous update was at 05:08 AM ----------

It will be grateful ,if u explain me what the command statement doing exactlySmilieerl -pe 's/([^ \047]*$x)(\047,)?.*/^^^^^$1^^^^^$2/' so that i can able to solve my problem

Last edited by Scott; 07-20-2013 at 05:28 PM.. Reason: This post is a mess. Please take better care in formatting your posts.
# 10  
Old 07-20-2013
If you want to have the search string taken from a variable, then use this:
Code:
perl -pse 's/([^ \047]$x)(\047,)?.*/^^^^^$1^^^^^$2/' -- -x="$x" /final.txt

# 11  
Old 07-25-2013
Thank you for your help.i wil check that now and infrom you on the same

---------- Post updated at 08:33 AM ---------- Previous update was at 08:11 AM ----------

Hi Bartus..

I have tried using the script:
Code:
perl -pse 's/([^ \047]$x)(\047,)?.*/^^^^^$1^^^^^$2/' -- -x="$x" /final.txt

but am not getting the desired output.........

simply my input data is coming.....

For ex:i/p file:validationtsttesting
desired o/p:validation^^^^^tst^^^^^
but o/p is coming as:validationtsttesting

can u plz help me in this.....

Last edited by Scott; 07-25-2013 at 11:42 AM.. Reason: Code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

2. Shell Programming and Scripting

Shell for displaying specific records from a line.

Input file. GMDCOM.27936 : Process Request <36812974> GMDCOM.27936 : Process Request <36812985> GMDCOM.27936 : Process Request <36812986> GMDCOM.27936 : Process Request <36812987> GMDCOM.27936 : Process Request <36812996> GMDCOM.27936 : Process Request <36812998> GMDCOM.27936 : Process... (14 Replies)
Discussion started by: ghosh_tanmoy
14 Replies

3. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

4. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: &quot;Liberation Sans&quot;; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

7. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

8. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

9. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question