Shell Scripting:Fetching content from each line with respect to pattern.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting:Fetching content from each line with respect to pattern.
# 1  
Old 10-26-2010
MySQL Shell Scripting:Fetching content from each line with respect to pattern.

one.txt
Code:
ONS.820.log:V[4.1] 20Oct2010:GP[^[KV001^] ^[tk003^] ^[338-1^]
ONS.123.log:V[4.1] 21Oct2010:GP[^[KV003^] ^[tk002^] ^[338-2^]
ONS.820.log:V[4.1] 30Oct2010:GP[^[KV002^] ^[tk001^] ^[338-3^]

want to make new file from existing one with addition.

Code:
20Oct2010 User KV001 has name tk003 with buffer- 338-1
21Oct2010 User KV003 has name tk002 with buffer- 338-2
30Oct2010 User KV002 has name tk001 with buffer- 338-3

The concept is match the multiple pattern and adding the string with pattern and modify the line.for example
ONS.820.log:V[4.1]- is deleted to make o/p.
GP[^[KV001^] - fetch only value from GP.
^[tk003^] -fetch only value and same with next.

Any expert comments on this?Smilie

Last edited by vgersh99; 10-26-2010 at 11:35 AM.. Reason: code tags, please!
# 2  
Old 10-26-2010
What have you tried so far and where exactly are you stuck?
You've had a very similar post already.
Please show the initial attempt!
# 3  
Old 10-26-2010
Code:
cat one.txt | tr -s "^[]:" " " | awk '{print $4" User "$6" has name "$7" with buffer "$8}'

# 4  
Old 10-26-2010
Hi

Thanks everone for help. Its really helpfull to post here.

Thanks once again.
# 5  
Old 10-26-2010
Useless cat, all in one-awk.

Code:
awk '{gsub(/\]|\[|\^|:/," ");print $4" User "$6" has name "$7" with buffer- "$8}' one.txt

20Oct2010 User KV001 has name tk003 with buffer- 338-1
21Oct2010 User KV003 has name tk002 with buffer- 338-2
30Oct2010 User KV002 has name tk001 with buffer- 338-3

# 6  
Old 10-26-2010
Code:
awk -F'[ [^:]' '{printf "%s User %s has name %s with buffer- %s\n",$4,$8,$12,$16}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cat command does not respect new line

Here's my script echo "1" >>hello.txt echo "2" >>hello.txt echo "3" >>hello.txt mailx -s "Check Status" #myteam@mycomp.com<hello.txt In Outlook I see EMail body as when I want it to be can you please suggest ? (29 Replies)
Discussion started by: mohtashims
29 Replies

2. Shell Programming and Scripting

Insert content of file before the first occurrence of a line starts with a pattern in another file

Hi all, I'm new to scripting.. facing some problems while inserting content of a file into another file... I want to insert content of a file (file2) into file1, before first occurrence of "line starts with pattern" in file1 file1 ====== working on linux its unix world working on... (14 Replies)
Discussion started by: Jagadeesh Kumar
14 Replies

3. Shell Programming and Scripting

Shell Scripting , need to search and print a line that contains a specific pattern

Take example of below file. abc.txt nas1:/abc/test/test1 /test nas1:/abc/test/test1/test2 /test/abc nas1:/abc/test/ Now i have a variable that contains "nas1:/abc/test/test1" value , so i need to search the above file for this variable and print only this line. ... (14 Replies)
Discussion started by: mohit_vardhani
14 Replies

4. Shell Programming and Scripting

Fetching a line matching a pattern

Hi Gurus, I have a file as follows (Sample shown below but the list is very huge) SCHEDULE WS1#JS1 RUNCYCLE1 : WS1#JOB1 WS1#JOB2 FOLLOWS JOB1 END SCHEDULE WS2#JS1 RUNCYCLE2 : WS1#JOB3 WS1#JOB1 FOLLOWS JOB3 WS2#JOB1 (10 Replies)
Discussion started by: jayadanabalan
10 Replies

5. Shell Programming and Scripting

Help with scripting-->Inserting a line before a pattern

Hi Guys, I have written the following script test.sh in Linux . read -p "Please enter the name of the application: " DIRTOCREATE read -p "Please enter the number of associates to be given access to svn:" COUNT for (( i=0 ; i<$COUNT ; i++ )) do read -p "Enter the associate id :"... (2 Replies)
Discussion started by: Pradeep_1990
2 Replies

6. Shell Programming and Scripting

Fetching string after matching pattern from last

I have a file a file having entries are like @ram@sham@sita @krishan@kumar @deep@kumar@hello@sham in this file all line are having different no of pattern-@. need to fetch the substring after the last pattern. like sita kumar sham thanks in advance (3 Replies)
Discussion started by: saluja.deepak
3 Replies

7. Shell Programming and Scripting

shell script to kill process with respect to terminal

Hi, I've a script which kills all process, but i need a script shell script(sh), where it'll kill process on that particular terminal. below is example TY=`tty` for P in $TY do `kill -9 $P 2>/dev/null`; done echo "test process killed" break ... (3 Replies)
Discussion started by: asak
3 Replies

8. Shell Programming and Scripting

Shell Scripting: Compare pattern in two files and merge the o/p in one.

one.txt ONS.1287677000.820.log 20Oct2010 ONS.1287677000.123.log 21Oct2010 ONS.1287677000.456.log 22Oct2010 two.txt ONS.1287677000.820.log:V AC CC EN ONS.1287677000.123.log:V AC CC EN ONS.1287677000.820.log:V AC CC EN In file two.txt i have to look for pattern which column one... (17 Replies)
Discussion started by: saluja.deepak
17 Replies

9. Shell Programming and Scripting

Pattern matching in shell scripting.

Hey Guys, I have a shell script that is very simple and does the following. #!/usr/bin/bash set -x echo -n "can you write device drivers?" read answer if then echo "wow, you must be very skilled" else echo "neither can i, i am just shell script" fi you see where the... (6 Replies)
Discussion started by: Irishboy24
6 Replies

10. Shell Programming and Scripting

Fetching just the matching pattern

Hi Everybody, I would like you to help me with the following problem. Given is a path to a file like this: /root/DIR/subdir/file.dat Having this path I would like to grep/sed or whatever the directory string that matches the following pattern ''. I just need the matching directory... (5 Replies)
Discussion started by: hhoosscchhii
5 Replies
Login or Register to Ask a Question