Sponsored Content
Top Forums Shell Programming and Scripting Script to change file contents line by line Post 302282848 by angheloko on Monday 2nd of February 2009 03:39:00 AM
Old 02-02-2009
Hope this helps:

Code:
sed '
h
s/^.\{8\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
G
s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
h
s/^.\{13\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
G
s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/' foo

Sample:
Code:
$ sed '
> h
> s/^.\{8\}\(.\).*/\1/
> y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
> G
> s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
> h
> s/^.\{13\}\(.\).*/\1/
> y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
> G
> s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/' foo
line1 aa1a xx4x
line2 bb1b yy4y
line3 cc1c zz4z

Also, you can save this to a file:
Code:
h
s/^.\{8\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/11111111111111111111111111/
G
s/\(.*\)\n\(.\{8\}\).\(.*$\)/\2\1\3/
h
s/^.\{13\}\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/44444444444444444444444444/
G
s/\(.*\)\n\(.\{13\}\).\(.*$\)/\2\1\3/

And the run it by:

Code:
sed -f foo.sed foo

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to echo the file contents LINE BY LINE

hello, i have a listing (let say ABC) consists of the below: : public database link public synonym role rollback segment : when i run the below for loop, for i in `more ABC` do echo "$i" done it gives me, : public database (4 Replies)
Discussion started by: newbie168
4 Replies

2. Shell Programming and Scripting

Search a pattern in a file with contents in a single line

Hi all I am searching for a pattern in a file . The file content is in a single line.If am doing a grep or sed for the a particular pattern am getting whole file. I want the result in different lines. attaching the file for reference search pattern "/xxxxxx/hhhh/tttttttt/sss/" and... (4 Replies)
Discussion started by: sparks
4 Replies

3. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies

4. Shell Programming and Scripting

Change a line in a php file thanks to a shell script

Hi, I'm working on a script to make automatic the new releases of my website... However in this script I put all the css script in a single one. There's no rpoblem for that. My problem is when I want to change the header of my layout page to put instead of : $header.="<link rel=\"stylesheet\"... (2 Replies)
Discussion started by: lahabana
2 Replies

5. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

6. Shell Programming and Scripting

change file contents using script

Hi, Requirement:- Need to change pfile,so while executing script,it has to go to pfile location(ORACLE_HOME/dbs) and open init<SID>.ora file and change value db_name=<>. If db_name=abcd,script will change the db_name=1234 likr that.. Please help to code this (1 Reply)
Discussion started by: Sanal
1 Replies

7. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

8. Shell Programming and Scripting

how to read the contents of two files line by line and compare the line by line?

Hi All, I'm trying to figure out which are the trusted-ips and which are not using a script file.. I have a file named 'ip-list.txt' which contains some ip addresses and another file named 'trusted-ip-list.txt' which also contains some ip addresses. I want to read a line from... (4 Replies)
Discussion started by: mjavalkar
4 Replies

9. Shell Programming and Scripting

Need script to change a line in file....

Hello all, I have a line of code in a file that I need to change in the /etc/sysconfig/kdump file presently the line reads: KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off" what I need to do is put a comment out the 1st line and repeat it, and... (5 Replies)
Discussion started by: gartie
5 Replies

10. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies
iso2022(5)							File Formats Manual							iso2022(5)

NAME
iso2022, iso-2022, ISO-2022 - A character encoding mechanism standardized by the International Standards Organization (ISO) DESCRIPTION
The ISO-2022 standard defines a mechanism for handling single-byte and multibyte characters. The standard specifies four classes of charac- ter sets: The 94-charset class, which contains character sets with 94 positions (single-byte characters). Examples are the ASCII and JIS X0201 character sets. The 96-charset class, which contains character sets with 96 positions (single-byte characters). Examples are the ISO Latin series of character sets. The 94x94-charset class, which contains character sets with 94x94 positions (2-byte characters). Examples are the GB 2312 and the CNS 11643 character sets. The 96x96-charset class, which contains character sets with 96x96 positions (2-byte characters). In the ISO-2022 standard, four registers, called G0, G1, G2 and G3, are used to reference a character set. Before a character set can be used, the character set must be assigned, or designated, to one of these registers. The designation of a character set is done by using an escape sequence in the following format: ESC [I] F In this format: Is an intermediate character that is used to designate a character set to one of the registers (G0, G1, G2, oR G3). Is a unique final character of a particular character set. The designation of a character set, whose final character is F, to different registers is as follows: Designates a multibyte character set (94x94 or 96x96) to G0. Designates a character set in the 94-charset class to G0. Designates a character set in the 94-charset class to G1. Designates a character set in the 94-charset class to G2. Designates a character set in the 94-charset class to G3. Designates a character set in the 96-charset class to G1. Designates a character set in the 96-charset class to G2. Designates a character set in the 96-charset class to G3. SEE ALSO
Commands: locale(1) Others: ascii(5), i18n_intro(5), iso2022jp(5), l10n_intro(5) iso2022(5)
All times are GMT -4. The time now is 07:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy