LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 04: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, 06:17 PM   #2
drawde83
Member
 
Registered: May 2006
Location: New Zealand
Distribution: ubuntu, gentoo at uni
Posts: 31

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

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

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk 'BEGIN{FS=": "}{ print $2 }' file* > outfile
 
Old 05-10-2007, 03: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, 03: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, 05:30 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
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, 06:15 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

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

The OP stated that fields are tab separated.
 
Old 05-11-2007, 02: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



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 57 04-17-2016 06:07 PM
how to program in shell to get a part of a file by line number George2 Linux - General 2 11-19-2006 02: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 07:16 AM
Script to read line by line from a file kushalkoolwal Programming 20 01-27-2006 04:17 AM
Shell script to copy file name with part of directory Transition Linux - General 5 01-18-2005 05:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration