sed and whitespace characters


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users sed and whitespace characters
# 1  
Old 07-03-2008
sed and whitespace characters

I have teh follwing details in a file:

SmithA..... ,,400
JonesA..... ,,300
JamesA..... ,,600
BakerA ,,800
ChrisA ,,1200


the first field name is 6 characters in length always and alays ends with an 'A'.
The periods denote white space (space caharacters), as you can see on certain occurences ther are many 'spaces' and in other instances no 'spaces'.

I want to be able to make the above file as below:

SmithA. ,,400
JonesA. ,,300
JamesA. ,,600
BakerA. ,,800
ChrisA. ,,1200


So anly one single whitespace is present after the las 'A' character.
I have treied the following,

sed 's/ *//g' fileA > fileB
which gives me:

SmithA ,,400
JonesA ,,300
JamesA ,,600
BakerA ,,800
ChrisA ,,1200

however i am now not so sure how to put a whitecase character back in after the A to get the format as required above.
Could anyone assist, also would perferably be ideal if i could have the whole thing processed in one single sed command.
# 2  
Old 07-03-2008
Try this:

Code:
sed 's/\(......\).*\(,,.*\)/\1 \2/' fileA > fileB

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies

3. UNIX for Dummies Questions & Answers

[Solved] How remove leading whitespace from xml (sed /awk?)

Hi again I have an xml file and want to remove the leading white space as it causes me issues later in my script I see sed is possible but cant seem to get it to work I tried sed 's/^ *//' file.xml output <xn:VsDataContainer id="1U104799" modifier="update"> ... (10 Replies)
Discussion started by: aniquebmx
10 Replies

4. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

5. Shell Programming and Scripting

Sed: Remove whitespace between two strings

I have a 13 number string, some whitespace, and then /mp3. I need to join them. Everyline that I need this for begins with "cd" (without the quotes). What it looks like now: cd media/Audio/WAVE/9781933976334 /mp3 What I want my output to be: cd media/Audio/WAVE/9781933976334/mp3 The 13... (7 Replies)
Discussion started by: glev2005
7 Replies

6. Shell Programming and Scripting

How to match (whitespace digits whitespace) sequence?

Hi Following is an example line. echo "192.22.22.22 \"33dffwef\" 200 300 dsdsd" | sed "s:\(\ *\ \):\1:" I want it's output to be 200 However this is not the case. Can you tell me how to do it? I don't want to use AWK for this. Secondly, how can i fetch just 300? Should I use "\2"... (3 Replies)
Discussion started by: shahanali
3 Replies

7. UNIX for Dummies Questions & Answers

use sed to replace whitespace with a carriage return

Greetings I need to replace "whitespace" in a file with the newline character aka carriage return My command is either wrong or not interpreted properly by me shell sed s/" "/\\n" "/g nets > nets1 or sed s/" "/\n" "/g nets > nets1 nets (input file) 13MHZ_IN... (4 Replies)
Discussion started by: awk_sed_hello
4 Replies

8. Shell Programming and Scripting

sed : remove whitespace

I'm trying to remove the whitespace at the end of each line of a text file in ksh. Im using sed s/ $//g' file1.txt > file2.txt It's not working. Any clues? (3 Replies)
Discussion started by: b.hamilton
3 Replies

9. Shell Programming and Scripting

SED to extract characters

Hi, Please let me know how do we write a piece of code to extract characters from a line using SED. (2 Replies)
Discussion started by: Shilpi
2 Replies

10. Shell Programming and Scripting

SED: Matching a string with whitespace?

I am trying to search through a text file and replace the number 1 at the beginning of the string in the second field with the number 9. There maybe one or more occurrences of whitespace between the string GPA131 and 17049333610. Does anyone know how to do this with sed? GPA131 17049333610 ... (1 Reply)
Discussion started by: cstovall
1 Replies
Login or Register to Ask a Question