SED: Matching a string with whitespace?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED: Matching a string with whitespace?
# 1  
Old 06-07-2005
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

After the search and replace the output file should read as follows:

GPA131 97049333610
# 2  
Old 06-07-2005
echo 'GPA131 17049333610 128374' | sed 's/^\([^ ][^ ]*[ ]*\)1\(.*\)/\19\2/'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Programming

Annoying whitespace after a char string...

Greetings everyone! I keep getting a very long whitespace after some char strings I'm outputting. This is the function where I input the names, last names...: void add_to_list (void) /* Add a new name to our address book */ { ADDRESS *new_name; FILE *outfile; new_name=... (4 Replies)
Discussion started by: Nephilim.F
4 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Help with sed matching <tag1> newline spaces <tag2> and replace the value in the same string format

Hi, I'm very new to shell scripting and have searched google and this forum for quite some time now. I have the following in my xml file: <recipients> <member>value1</member> </recipients> I need to find a string <recipients> that follows with a new-line and bunch of spaces and... (5 Replies)
Discussion started by: mgharios
5 Replies

6. 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

7. UNIX for Advanced & Expert Users

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... (1 Reply)
Discussion started by: SAMZ
1 Replies

8. Shell Programming and Scripting

null string matching in sed?

Hello, I would assume the expression ^$ should match a null string. Yet when I run: echo -n | sed 's/^$/nullstring/' I get no output. Can anyone tell me why? (6 Replies)
Discussion started by: Allasso
6 Replies

9. 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

10. Shell Programming and Scripting

sed problem - replacement string should be same length as matching string.

Hi guys, I hope you can help me with my problem. I have a text file that contains lines like this: 78 ANGELO -809.05 79 ANGELO2 -5,000.06 I need to find all occurences of amounts that are negative and replace them with x's 78 ANGELO xxxxxxx 79... (4 Replies)
Discussion started by: amangeles
4 Replies
Login or Register to Ask a Question