Removing spaces from record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing spaces from record
# 1  
Old 04-08-2010
Removing spaces from record

HI

i have record as shown below

Code:
402665,4X75,754X_FERNIE BC,12F2,008708,FERNIE BC,1,UTC   ,UTC   ,250
402665,4X75,754X_FERNIE BC,F212,008708,FERNIE BC,1,UTC   ,UTC   ,250
402665,4Y75,754Y_FERNIE BC,22F2,008708,FERNIE BC,1,UTC   ,UTC   ,250

here i want to remove multiple spaces into no space , i mean i want to remove
spaces after UTC , like ..

Code:
402665,4X75,754X_FERNIE BC,12F2,008708,FERNIE BC,1,UTC,UTC,250

how can i do it with awk ?

Thanks,

Last edited by vgersh99; 04-08-2010 at 08:04 AM.. Reason: code tags, please!
# 2  
Old 04-08-2010
Its simple using sed command.

Here is the demo:
Code:
$ echo "HELLO THIS IS AN EXAMPLE" | sed 's/ //g'
HELLOTHISISANEXAMPLE

so, ur command would be
Code:
sed 's/ //g' inputfilename > outputfilename

# 3  
Old 04-08-2010
Below command will statisfy any number of space.

Code:
sed 's/ *//g' inputfilename > outputfilename

Input:
402665,4X75,754X_FERNIE BC,12F2,008708,FERNIE BC,1,UTC ,UTC ,250
402665,4X75,754X_FERNIE BC,F212,008708,FERNIE BC,1,UTC ,UTC ,250
402665,4Y75,754Y_FERNIE BC,22F2,008708,FERNIE BC,1,UTC ,UTC ,250

Output:
402665,4X75,754X_FERNIEBC,12F2,008708,FERNIEBC,1,UTC,UTC,250
402665,4X75,754X_FERNIEBC,F212,008708,FERNIEBC,1,UTC,UTC,250
402665,4Y75,754Y_FERNIEBC,22F2,008708,FERNIEBC,1,UTC,UTC,250
# 4  
Old 04-08-2010
you can try
sed 's/UTC */UTC/g' your_file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to add blank spaces at the end of every record in a file.

hi, Does anyone has any idea in adding few blank spaces at the end of every record in a file. Eg: file.txt Baby Boy Kim 1234 Baby Boy Vik 1334 Desired output:- output.txt Baby Boy Kim 1234 Baby Boy Vik 1334 I want to add 10 blank spaces at the end every record in file.txt (3 Replies)
Discussion started by: techmoris
3 Replies

2. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

3. Shell Programming and Scripting

Removing \n within a record (awk/gawk)

I am using a solution that was provided by a member: awk '{s=$0;if(length(s) < 700){getline; s=s " " $0}printf("%s\n",s)}' This scans through a file and removes '\n' within a record but not the record delimiter. However, there are instances where there are MULTIPLE instances of '\n'... (10 Replies)
Discussion started by: CKT_newbie88
10 Replies

4. Shell Programming and Scripting

Removing \n within a fixed width record

I am trying to remove a line feed (\n) within a fixed width record. I tried the tr -d ‘\n' command, but it also removes the record delimiter. Is there a way to remove the line feed without removing the record delimiter? (10 Replies)
Discussion started by: CKT_newbie88
10 Replies

5. UNIX for Dummies Questions & Answers

Removing spaces...

Hey, I'm using the command from this thread https://www.unix.com/unix-dummies-questions-answers/590-converting-list-into-line.html to convert vertical lines to horzontal lines. But I need to remove the spaces that is created. Unfortunately I can't figure out where the space is in the code.. I... (2 Replies)
Discussion started by: lost
2 Replies

6. Shell Programming and Scripting

Adding spaces to record

Hi, I want to print spaces in a trailer record which is a single command. namely the unix command which i already have recs=`wc -l $TargetFileDir/myfile.txt|cut -c1-9`;export recs;echo 'PCPC.DXDINPT.FC0.INPUTFLE.PASS'`date +%Y%m%d``printf '%015d\n' $recs` >> $TargetFileDir/myfile1.txt I... (3 Replies)
Discussion started by: nvenkat010
3 Replies

7. Shell Programming and Scripting

appending spaces to first line based on second record.

Hi, I have a situation to append spaces to end of first record (header)and last record (footer) based on second record length. The first record length is always 20.The second record will be different for different files.I have to append spaces for the first line based on second record... (2 Replies)
Discussion started by: ammu
2 Replies

8. Shell Programming and Scripting

Inserting spaces in a record

Hi all. I am using /bin/sh on an HPUX system. I have a file, with records as such: 60701006000000030380000000000000030380000400000000000 61001006000000008220000000000000008220000100000000000 61201006000000030150000000000000030150001000000000000 I know the character counts which... (5 Replies)
Discussion started by: lyoncc
5 Replies

9. Shell Programming and Scripting

removing spaces

hey.. i had a problem with the unix command when i want to remove the white spaces in a string..i guess i cud do it with a sed command but i get an error when i give space in the square brackets.. string="nh hjh llk" p=`echo $string | sed 's/ //g'` i donno how to give space charater and... (2 Replies)
Discussion started by: sahithi_khushi
2 Replies

10. UNIX for Dummies Questions & Answers

Removing spaces between records

Hi I have an XML file. Which has spaces between different records.... current file( Has many lines, like this... I want to delete all the spaces between > and <, if there are only spaces between them) input file <xyzr> <abc>1234</xyzr> <aaa> <bbb> ayz mnz</bbb> <sen>KEA... (6 Replies)
Discussion started by: thanuman
6 Replies
Login or Register to Ask a Question