Sponsored Content
Top Forums Shell Programming and Scripting By using "sed" command. Please help!!! Post 302419423 by nvkuriseti on Friday 7th of May 2010 10:25:36 AM
Old 05-07-2010
Hello,

My input files are having header/body/footer. The first three digits finds whether the data is header/body/footer. For example,

Code:
010AAAAA 20100507 234KB BBBBBBBBBB_20100506.DAT
020CCCCC                     DDDDDDDDD         373983983           19750426           456.90               3983939EE
020FFFFF                     GGGGGGGGG         38938993H           19801102           783.33               DKJFDKJ983
030END OF FILE TOTAL 39839.22

From the above file, there is a date of birth in body (=020). I want to remove/substitute the dateofbirth with spaces. Like, 19750426 is the date of birth but want to substiute as spaces "1#7#0#2#". Want to do this same in all records in the file. Can you please tell me how to do this in shell script?

Code:
The content of the file is,
From 1 to 3 = RECORD_TYPE
From 4 to 40 = NAME
From 41 to 80 = DESIGNATION
and so on.

A small change in my previous post. Instead of substitue the spaces, need to fill every 2nd character as # in the Date of Birth field.

---------- Post updated at 10:25 AM ---------- Previous update was at 06:00 AM ----------

dr.house! Thanks for your coding. But I tried and it is still giving the same input file content as result Smilie

Last edited by nvkuriseti; 05-07-2010 at 07:17 AM.. Reason: Code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

2. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

5. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Post Here to Contact Site Administrators and Moderators

Suggestion: adding two new groups "sed" and "awk"

Majority of the questions are pertaining file/string parsing w.r.t sed or awk It would be nice to have these two as their own sub category under shell-programming-scripting which can avoid lot of duplicate posts. (1 Reply)
Discussion started by: jville
1 Replies

8. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

9. Shell Programming and Scripting

Awk,sed : change every 2nd field ":" to "|"

Hi Experts, I have a string with colon delimited, want 2nd colon to be changed to a pipe. data: 101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3: I am trying with sed, but can change only 1 occurance: echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Discussion started by: rveri
5 Replies

10. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies
nl(1)								   User Commands							     nl(1)

NAME
nl - line numbering filter SYNOPSIS
/usr/bin/nl [-p] [-b [type]] [-d [delim]] [-f [type]] [-h [type]] [-i [incr]] [-l [num]] [-n [format]] [-s [sep]] [-w [width]] [-v [startnum]] [file] /usr/xpg4/bin/nl [-p] [-b type] [-d delim] [-f type] [-h type] [-i incr] [-l num] [-n format] [-s sep] [-w width] [-v startnum] [file] DESCRIPTION
The nl utility reads lines from the named file, or the standard input if no file is named, and reproduces the lines on the standard output. Lines are numbered on the left in accordance with the command options in effect. nl views the text it reads in terms of logical pages. Line numbering is reset at the start of each logical page. A logical page consists of a header, a body, and a footer section. Empty sections are valid. Different line numbering options are independently available for header, body, and footer. For example, -bt (the default) numbers non-blank lines in the body section and does not number any lines in the header and footer sections. The start of logical page sections are signaled by input lines containing nothing but the following delimiter character(s): +-----------------------------+-----------------------------+ | Line contents | Start Of | +-----------------------------+-----------------------------+ |::: |header | +-----------------------------+-----------------------------+ |:: |body | +-----------------------------+-----------------------------+ |: |footer | +-----------------------------+-----------------------------+ Unless optioned otherwise, nl assumes the text being read is in a single logical page body. OPTIONS
Command options may appear in any order and may be intermingled with an optional file name. Only one file may be named. The specified default is used when the option is not entered on the command line. /usr/xpg4/bin/nl options require option arguments. A SPACE character may separate options from option arguments. /usr/bin/nl options may have option arguments. If option-arguments of /usr/bin/nl options are not specified, these options result in the default. The supported options are: -btype Specifies which logical page body lines are to be numbered. Recognized types and their meanings are: a number all lines t number all non-empty lines. n no line numbering pexp number only lines that contain the regular expression specified in exp. See NOTES below. Default type for logical page body is t (text lines numbered). -ftype Same as -btype except for footer. Default type for logical page footer is n (no lines numbered). -ddelim The two delimiter characters specifying the start of a logical page section may be changed from the default characters (:) to two user-specified characters. If only one character is entered, the second character remains the default character (:). No space should appear between the -d and the delimiter characters. To enter a backslash, use two backslashes. -htype Same as -btype except for header. Default type for logical page header is n (no lines numbered). -iincr incr is the increment value used to number logical page lines. Default incr is 1. -lnum num is the number of blank lines to be considered as one. For example, -l2 results in only the second adjacent blank being numbered (if the appropriate -ha, -ba, and/or -fa option is set). Default num is 1. -nformat format is the line numbering format. Recognized values are: ln left justified, leading zeroes suppressed rn right justified, leading zeroes suppressed rz right justified, leading zeroes kept Default format is rn (right justified). -p Do not restart numbering at logical page delimiters. -ssep sep is the character(s) used in separating the line number and the corresponding text line. Default sep is a TAB. -vstartnum startnum is the initial value used to number logical page lines. Default startnum is 1. -wwidth width is the number of characters to be used for the line number. Default width is 6. OPERANDS
The following operand is supported: file A path name of a text file to be line-numbered. EXAMPLES
Example 1 An example of the nl command The command: example% nl -v10 -i10 -d!+ filename1 will cause the first line of the page body to be numbered 10, the second line of the page body to be numbered 20, the third 30, and so forth. The logical page delimiters are !+. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of nl: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 Successful completion. >0 An error occurred. FILES
/usr/lib/locale/locale/LC_COLLATE/CollTable Collation table generated by localedef /usr/lib/locale/locale/LC_COLLATE/coll.so Shared object containing string transformation library routines ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin/nl +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ /usr/xpg4/bin/nl +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
pr(1), attributes(5), environ(5), regex(5), regexp(5), standards(5) NOTES
Internationalized Regular Expressions are used in the POSIX and "C" locales. In other locales, Internationalized Regular Expressions are used if the following two conditions are met: o /usr/lib/locale/locale/LC_COLLATE/CollTable is present. o /usr/lib/locale/locale/LC_COLLATE/coll.so is not present. Otherwise, Simple Regular Expressions are used. Internationalized Regular Expressions are explained on regex(5). Simple Regular Expressions are explained on regexp(5). SunOS 5.11 28 Mar 1995 nl(1)
All times are GMT -4. The time now is 02:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy