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.
# 8  
Old 10-30-2013
You cat also try this:
Code:
cat input_file | awk '{print $NF,$2,$3,$4,$5,$6}' | tr -d "<>" | sed 's/.\{1\}$//'


Last edited by Scrutinizer; 10-30-2013 at 07:16 AM.. Reason: code tags added
# 9  
Old 10-30-2013
Quote:
You cat also try this:
cat input_file | awk '{print $NF,$2,$3,$4,$5,$6}' | tr -d "<>" | sed 's/.\{1\}$//'
kunal,

There is no need for cat as awk takes it.

so it may be as follows.

Code:
awk '{print $NF,$2,$3,$4,$5,$6}' input_file | tr -d "<>" | sed 's/.\{1\}$//'


Thanks,
R. Singh
# 10  
Old 10-30-2013
Quote:
Originally Posted by RavinderSingh13
kunal,

There is no need for cat as awk takes it.

so it may be as follows.

Code:
awk '{print $NF,$2,$3,$4,$5,$6}' input_file | tr -d "<>" | sed 's/.\{1\}$//'


Thanks,
R. Singh
Thanks for correcting me, Yes we can do that with awk only

Kunal
# 11  
Old 10-30-2013
@RavinderSingh13:
Code:
sed 's/GMDCOM.27936 //g

Why only for GMDCOM.27936? What happens when there are records with something else in field 1? The . should be escaped: \.. The global flag (g) is not necessary
Code:
s/\://g;s/\<//g;s/\>//g

These characters do not need a "\" . You can put this in one statement like so:
Code:
s/[:<>]//g

Code:
awk '{print$8" "$1" "$2" "$3" "$4" "$5}'

Since the default OFS is a single space, you can use , instead:
Code:
awk '{print $8, $1, $2, $3, $4, $5}'



---
@kunal37
Code:
sed 's/.\{1\}$//'

is the same as
Code:
sed 's/.$//'

This User Gave Thanks to Scrutinizer For This Post:
# 12  
Old 10-30-2013
one more solution with sed for given sample :
Code:
sed -e 's/.*\(\[.*\]\).*<\(.*\)>$/\2 \1/' input_file

# 13  
Old 10-30-2013
---
@kunal37
Code:
sed 's/.\{1\}$//'

is the same as
Code:
sed 's/.$//'

[/QUOTE]

Thanks Scrutinizer Smilie
# 14  
Old 10-30-2013
Shell to display portion of a line

Hi Ravinder,

I have understood the awk portion of the code. But please can you explain the SED portion.
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