LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-02-2010, 07:31 AM   #1
Met_girl
LQ Newbie
 
Registered: Nov 2010
Location: UK
Posts: 2

Rep: Reputation: 0
Removing specific field seperator to combine two fields


Hello all, here is my first post!

I am trying to remove the space between the 2nd and 3rd fields but just cannot work out how to do it. I've considered sed, cut, awk...
I know with sed you can replace all instances within a file but can you also specify to remove, say, the 2nd instance of a space in each line (this would be perfect for me)?

DAAE 60 402 Bejaia Algeria 1 36-43N 005-04E 36-43N 005-04E 2 2 P
DAAG 60 390 Dar-El-Beida Algeria 1 36-43N 003-15E 36-43N 003-15E 25 25 P
DAAJ 60 670 Djanet Algeria 1 24-33N 009-28E 24-33N 009-28E 1054 1054 P
DAAP 60 640 Illizi Algeria 1 26-30N 008-25E 26-30N 008-25E 558 558 P
DAAS 60 445 Setif Algeria 1 36-11N 005-25E 36-11N 005-25E 1038 1081 P
DAAV 60 351 Jijel Achouat Algeria 1 36-53N 005-49E 2 10 P
DAAY 60 549 Mecheria Algeria 1 34-56N 000-26W 34-56N 000-26W 1149 1149 P

Thanks everyone.
 
Old 12-02-2010, 07:42 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,505

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by Met_girl View Post
Hello all, here is my first post!

I am trying to remove the space between the 2nd and 3rd fields but just cannot work out how to do it. I've considered sed, cut, awk...
I know with sed you can replace all instances within a file but can you also specify to remove, say, the 2nd instance of a space in each line (this would be perfect for me)?

DAAE 60 402 Bejaia Algeria 1 36-43N 005-04E 36-43N 005-04E 2 2 P
DAAG 60 390 Dar-El-Beida Algeria 1 36-43N 003-15E 36-43N 003-15E 25 25 P
DAAJ 60 670 Djanet Algeria 1 24-33N 009-28E 24-33N 009-28E 1054 1054 P
DAAP 60 640 Illizi Algeria 1 26-30N 008-25E 26-30N 008-25E 558 558 P
DAAS 60 445 Setif Algeria 1 36-11N 005-25E 36-11N 005-25E 1038 1081 P
DAAV 60 351 Jijel Achouat Algeria 1 36-53N 005-49E 2 10 P
DAAY 60 549 Mecheria Algeria 1 34-56N 000-26W 34-56N 000-26W 1149 1149 P

Thanks everyone.
A bit confused...if you know you can do it in sed, why didn't you DO it? Lots of documentation/examples can be found via Google.

Try "sed 's/ //2'".
 
Old 12-02-2010, 08:37 AM   #3
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 532

Rep: Reputation: 78
This will do it too:
Code:
awk '{ print $1, $2$3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13 }'
 
Old 12-02-2010, 08:38 AM   #4
Met_girl
LQ Newbie
 
Registered: Nov 2010
Location: UK
Posts: 2

Original Poster
Rep: Reputation: 0
I said I knew how to take out ALL instances using sed but couldn't work out how to specify just a particular part of a line.

[Try "sed 's/ //2'"] - yep it worked! I didn't know that placing the 2 there specified which one to take out.

Thanks.
 
  


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
how to grep for only the values of a specific field hchoonbeng Linux - Newbie 3 11-19-2008 08:20 AM
how not to print the 4th field from a text file with six fields livetoday Red Hat 3 10-02-2007 01:19 PM
Unique lines based on specific fields. carl.waldbieser Programming 6 08-21-2005 02:26 PM
Replacing text in a specific field Seventh_Warrior Programming 5 04-11-2005 12:04 PM
search for specific text in fields using awk Helene Programming 2 04-23-2004 12:13 AM


All times are GMT -5. The time now is 12:58 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration