The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
aside from paste kenshinhimura Shell Programming and Scripting 3 03-11-2008 01:16 AM
Paste Script Help Dangrim1 Shell Programming and Scripting 1 01-17-2007 11:06 PM
Cut Paste and Insert Help PradeepRed Shell Programming and Scripting 5 12-09-2005 05:49 AM
awk or sed or paste leprichaun UNIX for Dummies Questions & Answers 3 11-16-2003 07:58 PM
Cut, Copy and Paste with X auswipe UNIX Desktop for Dummies Questions & Answers 4 03-27-2002 04:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2005
t_harsha18 t_harsha18 is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 2
cut & paste

hi i am new to shell scripting,
i have been trying to cut columns numbered 1,4 of a file consisiting of 4 columns. Each column is seperated by 2 spaces.
for example:
john 6102097199 tennessee usa
michel 6734590899 texas USA
now, i need to cut the name and country column and paste it in another file.

I used the delimiter with 2 spaces using 'cut' function and pasted using 'paste' function to paste it in another file. But, this did'nt work
CAN ANYONE PLEASE HELP ME OUT WITH THIS?????????????????????
  #2 (permalink)  
Old 10-02-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Here is an awk solution.

Code:
awk '{ print $1,$4 }' entry.txt > output.file
If there are more than 4 columns and the country colume always appears last with name in the first column, then here is a more generalized solution.

Code:
awk '{ print $1,$NF }' entry.txt > output.file
vino

Last edited by vino; 10-02-2005 at 04:17 AM.. Reason: Changing $NR to $NF
  #3 (permalink)  
Old 10-02-2005
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Quote:
Originally Posted by vino
Here is an awk solution.

Code:
awk '{ print $1,$4 }' entry.txt > output.file
If there are more than 4 columns and the country colume always appears last with name in the first column, then here is a more generalized solution.

Code:
awk '{ print $1,$NR }' entry.txt > output.file
vino
Code:
awk '{ print $1,$NF }' entry.txt > output.file
  #4 (permalink)  
Old 10-02-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Thanks futurelet! That was a typo. F and R are too close to each other.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0