Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing extra space characters

Status
Not open for further replies.

buzzcasper

Technical User
Jan 14, 2003
7
US
Here's an example of what data I'm trying to work with:

s 835977258
s 262188
q 640942125
q 1348337710
q 126091311
m 26219
m 1343881270
m 134859986

I'm looking to remove the extra spaces between the first character and the second field pid id. I'm still researching my options possibly with using a sed command but I want to know if there's an easier way to eliminate any extra spaces after the second character which is a space.
 
But that will eliminate all the spaces where I need one to exist in the second character spot.
 
in KornShell:

Code:
while read
do
echo $REPLY
done < file > newfile

This works because the read first parses the input line into fields using IFS (Internal Field Separator), which by default considers multiple spaces as a single field separator. Since no variable names were passed to the read for assignment, all of the fields are then concatenated using the first character of IFS and placed in the REPLY variable. By default, that character is a space. IFS is reset to the default before execution of a script begins, so there's no need to set it explicitly in your own script unless you've modified it earlier in that same script.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top