The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Stripping the spaces in a string variable rag84dec Shell Programming and Scripting 3 03-27-2008 03:16 AM
ksh - read file with leading spaces momi Shell Programming and Scripting 2 03-17-2008 03:02 PM
remove leading spaces from a line lijojoseph Shell Programming and Scripting 6 03-17-2008 05:29 AM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 11:48 PM

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

Join Date: Feb 2006
Posts: 2
Stripping leading spaces on right justified name

I have a name field in a file which is right justified (yep - its true). I need to strip the leading spaces from the field and write the name out left justified. Again, I think I need to use a sed or awk command but so far, my results are at best disappointing. Thank you in advance from a UNIX newbie.

I need to leave the other fields intact, even if they have spaces. Is there no way to give a start and end position for a UNIX command to look at ?

Thanks
MArcia P
  #2 (permalink)  
Old 02-28-2006
nuggetz nuggetz is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 8
Does this file have set columns? If so you could use awk to extract the last field in the file. If so, then you can use awk like this, if not, I'll defer until more info is provided:

cat file | awk '{print $5}' where $5 is the fifth column in the file.
  #3 (permalink)  
Old 02-28-2006
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Gawk allows you to specify field widths, strip leading spaces from a field and print out in a new format, e.g...
Code:
$ cat file1
1000          dingo1000
2000    bingo bongo2000

$ gawk 'BEGIN{FIELDWIDTHS="4 15 4"}{sub(/ +/,"",$2);printf "%4s%-15s%4s\n",$1,$2,$3}' file1
1000dingo          1000
2000bingo bongo    2000
Sponsored Links
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 11:26 PM.


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