Shell for displaying specific records from a line.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell for displaying specific records from a line.
# 1  
Old 10-30-2013
Shell for displaying specific records from a line.

Input file.
Code:
GMDCOM.27936 [Tue Oct  1 13:32:40 2013]: Process Request <36812974>
GMDCOM.27936 [Tue Oct  1 13:37:38 2013]: Process Request <36812985>
GMDCOM.27936 [Tue Oct  1 13:37:53 2013]: Process Request <36812986>
GMDCOM.27936 [Tue Oct  1 13:37:54 2013]: Process Request <36812987>
GMDCOM.27936 [Tue Oct  1 13:37:57 2013]: Process Request <36812996>
GMDCOM.27936 [Tue Oct  1 13:38:06 2013]: Process Request <36812998>
GMDCOM.27936 [Tue Oct  1 13:38:14 2013]: Process Request <36813001>
GMDCOM.27936 [Tue Oct  1 13:38:20 2013]: Process Request <36813004>
GMDCOM.27936 [Tue Oct  1 13:38:27 2013]: Process Request <36813007>
GMDCOM.27936 [Tue Oct  1 13:38:29 2013]: Process Request <36813009>


Output file should be in the below format.
Code:
36812974 [Tue Oct  1 13:32:40 2013]
36812985 [Tue Oct  1 13:37:38 2013]
36812986 [Tue Oct  1 13:37:53 2013]

and it continues till the end of the file and displays all the records in the above format.
# 2  
Old 10-30-2013
I suggest you read the man page of the cut command. Field separator is per default a single blank, but you can specify any other character with the -d '<character>' option.

I hope this helps.

bakunin
# 3  
Old 10-30-2013
Shell to display portion of a line

Not giving the desired output.
# 4  
Old 10-30-2013
Or try something like this:
Code:
awk -F'[]<>[]' '{print $4, "[", $2, "]"}' file

# 5  
Old 10-30-2013
Shell to display portion of a line

Please help me by explaining the code.
# 6  
Old 10-30-2013
Hi,

Please use the following code.

Code:
sed 's/GMDCOM.27936 //g;s/\://g;s/\<//g;s/\>//g' file_name | awk '{print$8" "$1" "$2" "$3" "$4" "$5}'

Output will be as follows.


Code:
36812974 [Tue Oct 1 133240 2013]
36812985 [Tue Oct 1 133738 2013]
36812986 [Tue Oct 1 133753 2013]
36812987 [Tue Oct 1 133754 2013]
36812996 [Tue Oct 1 133757 2013]
36812998 [Tue Oct 1 133806 2013]
36813001 [Tue Oct 1 133814 2013]
36813004 [Tue Oct 1 133820 2013]
36813007 [Tue Oct 1 133827 2013]
36813009 [Tue Oct 1 133829 2013]


Thanks,
R. Singh

Last edited by RavinderSingh13; 10-30-2013 at 07:03 AM.. Reason: littile editing
# 7  
Old 10-30-2013
Quote:
Originally Posted by ghosh_tanmoy
Please help me by explaining the code.
It uses any of the character "[" "]" "<" or ">" as field separators (specified by the -F command line option). It then prints field 4 and field 2, the second embedded in "[" and " ]".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies

2. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

3. Shell Programming and Scripting

Korn Shell script to insert at specific line

Hi, I am trying to put together a Korn Shell script to insert at a specific line. The system we use is SunOS 5.10 I can get the line number by using:- num=`sed -n '/export ENV/=' ./tmp.file` Not getting much headway using the above variable's value to insert - export SYBASE=/opt/sybase15... (5 Replies)
Discussion started by: aj8200
5 Replies

4. Shell Programming and Scripting

How to read from specific line number in shell script?

I have a text file which is having 30000 lines in it. I have to create a xml file for each 10000 lines until all the lines in the text files are written. Also please help how can i get number of lines in the text file in a shell variable? (19 Replies)
Discussion started by: vel4ever
19 Replies

5. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

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)
Discussion started by: Atrisa
4 Replies

6. Homework & Coursework Questions

Displaying specific lines from a CSV file

1. The problem statement, all variables and given/known data: Display from a csv file, birthdays that occur today. If there are no birthdays today, the next one in the year. 2. Relevant commands, code, scripts, algorithms: The csv file is ordered from older to younger (ie. the most recent... (8 Replies)
Discussion started by: Adzi
8 Replies

7. UNIX for Dummies Questions & Answers

Displaying specific columns in a file

Hi, I'm just wondering how you display a specific set of columns of a specified file in Unix. For example, if you had an AddressBook file that stores the Names, Phone numbers, and Addresses of people the user entered in the following format (the numbers are just to give an idea of what column... (1 Reply)
Discussion started by: logorob
1 Replies

8. Shell Programming and Scripting

To print a specific line in Shell or awk.

Hi, I want to echo the 15th line from a file named as abc.txt, also i want to echo only the values in that line not the line number. Thanks in advance:) (4 Replies)
Discussion started by: tushar_tus
4 Replies

9. Shell Programming and Scripting

Displaying the Last Modification Time of a specific file

How can I get and display the last modification time of a file? in scripting or specifically using Batch file I want this info for me to determine whether an image has been edited or not by using the last modification time and compare it to our stored date of modification. can somebody help... (5 Replies)
Discussion started by: jaque18
5 Replies

10. UNIX for Dummies Questions & Answers

Displaying specific lines in a file.

I'm trying to figure out how to display a certain line in a text file. I keep getting references to Tail and Head, and I know how these work, but i'm lost on how to find say the third out of the five lines and display only that. I thought maybe grep could help, but that doesn't seem likely. ... (3 Replies)
Discussion started by: MaestroRage
3 Replies
Login or Register to Ask a Question