LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-09-2007, 05:38 PM   #1
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Rep: Reputation: 15
script to get a part of line from a file


Hello
I have a directory of several text files formatted as follwoing
[25.8376] [32.1000] B: xab~ir $uw fiy Eindak >axbaAr
[2.8376] [12.1000] B: xab $uw Gde Ginda >qwaAd
[100.8376] [200.1000] A: xab~ir $gd fhg Qwerak AssbaAr .
it appears that it has three parts seperated by \t tab,I want to get only the last part (red) of line and so on for whole file then all files
putting them in one file as output file formated as a words seperated by spaces

would you please help me to write a script to do that ??
thanx a lot
MD
 
Old 05-09-2007, 07:17 PM   #2
drawde83
Member
 
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 30

Rep: Reputation: 15
Code:
sed 's/^.*\t//' filename(s) > file to save to

Last edited by drawde83; 05-09-2007 at 07:19 PM.
 
Old 05-09-2007, 07:24 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
awk 'BEGIN{FS=": "}{ print $2 }' file* > outfile
 
Old 05-10-2007, 04:10 AM   #4
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by drawde83
Code:
sed 's/^.*\t//' filename(s) > file to save to

thank you its running
 
Old 05-10-2007, 04:12 AM   #5
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ghostdog74
Code:
awk 'BEGIN{FS=": "}{ print $2 }' file* > outfile
thank you
but It doesnt result out !
 
Old 05-10-2007, 06:30 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by mystical dervish
thank you
but It doesnt result out !
Code:
# awk 'BEGIN{FS=": "}{ print $2 }' file
xab~ir $uw fiy Eindak >axbaAr
xab $uw Gde Ginda >qwaAd
xab~ir $gd fhg Qwerak AssbaAr .
 
Old 05-10-2007, 07:15 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
Hi,

@ghostdog74: Shouldn't this:
FS=": "
be
FS=":\t"

The OP stated that fields are tab separated.
 
Old 05-11-2007, 03:57 AM   #8
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by druuna
Hi,

@ghostdog74: Shouldn't this:
FS=": "
be
FS=":\t"

The OP stated that fields are tab separated.

exactly !!!
thank you all
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 51 07-04-2013 09:16 PM
how to program in shell to get a part of a file by line number George2 Linux - General 2 11-19-2006 03:41 AM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 08:16 AM
Script to read line by line from a file kushalkoolwal Programming 20 01-27-2006 05:17 AM
Shell script to copy file name with part of directory Transition Linux - General 5 01-18-2005 06:40 PM


All times are GMT -5. The time now is 06:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration