Find string in a file and append character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find string in a file and append character
# 8  
Old 08-21-2012
Bug

I am getting below output....

Code:
$ cat temp_file
NULL
NULL
NULL
9,800.00
NULL
1,234,567.01

$ sed 's/^[0-9]/$1/g' temp_file
NULL
NULL
NULL
$1,800.00
NULL
$1,234,567.01

$ sed 's/^\([0-9]\)/$\1/' temp_file
NULL
NULL
NULL
$9,800.00
NULL
$1,234,567.01

# 9  
Old 08-21-2012
Quote:
Originally Posted by pamu
I am getting below output....

Code:
$ cat temp_file
NULL
NULL
NULL
9,800.00
NULL
1,234,567.01

$ sed 's/^[0-9]/$1/g' temp_file
NULL
NULL
NULL
$1,800.00
NULL
$1,234,567.01

$ sed 's/^\([0-9]\)/$\1/' temp_file
NULL
NULL
NULL
$9,800.00
NULL
$1,234,567.01

Yes! look at line #4!
This User Gave Thanks to RudiC For This Post:
# 10  
Old 08-21-2012
Thanks Rudic...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find string in file and append new string after

Hi All, I'm trying to insert a string into a file at a specific location. I'd like to add a string after the parent::__construct(); in my file. <?php if (! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Controller extends CI_Controller { function... (6 Replies)
Discussion started by: jjkilpatrick
6 Replies

2. Shell Programming and Scripting

To append Character in file

hi, i am having a file which is comma seperated , i need to append a char in particular column for eg: infile aa,bb,c,dd,ee zz,yy,sss,ddd,ff . . i need to append for eg 4th column with a char like 'LQ' output: aa,bb,c,LQdd,ee zz,yy,sss,LQddd,ff (12 Replies)
Discussion started by: rohit_shinez
12 Replies

3. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

4. Shell Programming and Scripting

Search for a string, then append character to end of that line only

I have 2 files that I am working with $ cat file1 server1 server3 server5 server6 server8 $ cat file2 server1;Solaris; server2; SLES; server3;Linux; server4; Solaris; server5;SLES; server6;SLES; server7;Solaris; server8;Linux; (1 Reply)
Discussion started by: snoman1
1 Replies

5. Shell Programming and Scripting

sed to find first appearance and append string

I have a file like below #GROUP A belongs to Asia GROUP A jojh hans local admin GROUP A gege fans michel jing jong #GROUP U belongs to USA GROUP U jeff goal hello world My requirement is to grep for first apperence of GROUP A which is not commented and append my name to end of file.... (12 Replies)
Discussion started by: vkk
12 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

7. Shell Programming and Scripting

How do I append a ^M to the end of each 129 character string

Hello all, I have a stumper of a problem. I am trying to append a ^M or "newline" to the end of each 129 character string in a huge file in unix. Each string starts with A00. I am trying to get the file to go from... A00vswjdv1 Test Junk Junk A00vswjdv2 Test Junk Junk ... (6 Replies)
Discussion started by: Captain
6 Replies

8. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies

9. UNIX for Dummies Questions & Answers

Find and replace character in a string

Hi all, My problem is the following: I've a script that must list all files in a directory and write this information in a text file. I've tried to get the list through ls command and then write it using msgecho msgecho "`ls $PATH_APS_JOB_ORA`" This works good but the created string... (7 Replies)
Discussion started by: callimaco0082
7 Replies

10. Programming

append character to a file

Hi, fputc() will overwrite from the beginning of the target file. How would I append characters to the target file's end instead? Thanks. (3 Replies)
Discussion started by: enuenu
3 Replies
Login or Register to Ask a Question