Sponsored Content
Top Forums Shell Programming and Scripting Insert lines between delimiters Post 302232458 by BMDan on Thursday 4th of September 2008 01:08:30 PM
Old 09-04-2008
Insert {file,stdin} between delimiters

I'm working with a file like:
Code:
somestuff
somemorestuff
...
someadditionalstuff
STARTTAG
ENDTAG
someotherstuff
somecoolstuff
...
somefinalstuff

I've got some text (either in a file or piped) to put between STARTTAG and ENDTAG. I was thinking something like grepping for the line number of STARTTAG and ENDTAG and doing appropriate head and tail and so forth, but it'd get ugly by the time I was done. Is there a cleaner/easier way? I know how to do it in Perl, but surely there's an easier/faster/better option.

Thanks!,
BMDan

Last edited by BMDan; 09-04-2008 at 02:29 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I insert commas/delimiters in File

Hi, Newbie here. Need to convert a txt file to .csv format. There's no character to replace so not sure if I can use sed :confused: . The comma is to be inserted after every certain number of characters in each line... Help! Thanks. (4 Replies)
Discussion started by: mbelen
4 Replies

2. Shell Programming and Scripting

parse of lines with different delimiters

Hi, I am having huge file with the following lines. 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7.FPN, message={SD=2007:10:01:00:00:00:GMT,SP=5,NP=2,TS=2007:10:01:01:00:00:GMT,VP=0.0,TS=2007:10:01:01:30:00:GMT,VP=0.0} 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7G.FPN,... (9 Replies)
Discussion started by: nathasha
9 Replies

3. Shell Programming and Scripting

commenting out lines between two delimiters

Hi All, I am struggling to get my head around the following issue. I am having to comment out lines between two delimiters by placing an asterix in position 7 but retain all lines in the file and in the same order. so for example a file containing: ... ... DELIM1 ... ... DELIM2... (2 Replies)
Discussion started by: Bruble
2 Replies

4. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

5. Shell Programming and Scripting

Concatinating the lines based on number of delimiters

Hi, I have a problem to concatenate the lines based on number of delimiters (if the delimiter count is 9 then concatenate all the fields & remove the new line char bw delimiters and then write the following data into second line) in a file. my input file content is Title| ID| Owner|... (4 Replies)
Discussion started by: bi.infa
4 Replies

6. Shell Programming and Scripting

awk: Print fields between two delimiters on separate lines and send to variables

I have email headers that look like the following. In the end I would like to accomplish sending each email address to its own variable, such as: user1@domain.com='user1@domain.com' user2@domain.com='user2@domain.com' user3@domain.com='user3@domain.com' etc... I know the sed to get rid of... (11 Replies)
Discussion started by: tay9000
11 Replies

7. Shell Programming and Scripting

Insert data between comma delimiters-large file

Having a huge file in the following format. 2,3,1,,,4 1,2,3,,,,,5, 8,7,3,4,,,, Output needed is: 2,3,1,0.0,0.0,4 1,2,3,0.0,0.0,0.0,0.0,5, 8,7,3,4,0.0,0.0,0.0, I have tried reading the file each line, using AWK to parse to find out ",," and then insert 0.0 . It works but very slow. Need... (8 Replies)
Discussion started by: wincrazy
8 Replies

8. Shell Programming and Scripting

Insert Columns before the last Column based on the Count of Delimiters

Hi, I have a requirement where in I need to insert delimiters before the last column of the total delimiters is less than a specified number. Say if the delimiters is less than 139, I need to insert 2 columns ( with blanks) before the last field awk -F 'Ç' '{ if (NF-1 < 139)} END { "Insert 2... (5 Replies)
Discussion started by: arunkesi
5 Replies

9. Shell Programming and Scripting

Grep lines only with 3 delimiters

Hi All, my file has following Data 04:38:34 02:03 24:40 02:09:58 09:13 03:04:11 02:09:58 35:00 I want to display only lines with 3 fields. ie.. 04:38:34 02:09:58 03:04:11 (6 Replies)
Discussion started by: Arunselvan
6 Replies

10. Shell Programming and Scripting

Insert a hyphen between two delimiters using sed

Hey guys, I have a file that is delimited by | and I am trying to write a sed command to convert this: abc|def||ghi|jkl||||mnop into this: abc|def|-|ghi|jkl|-|-|-|mnop The output I am getting out of: sed -e "s/+//g" /tmp/opt.del > /tmp/opt2.del is like: ... (9 Replies)
Discussion started by: prohank
9 Replies
tail(1) 						      General Commands Manual							   tail(1)

NAME
tail - deliver the last part of a file SYNOPSIS
number] [file] number] [file] number] [file] Obsolescent: [file] DESCRIPTION
copies the named file to the standard output beginning at a designated place. If no file is named, standard input is used. Command Forms can be used in three forms as indicated above: Copy file starting at number blocks from end or beginning of file. Copy file starting at number bytes from end or beginning of file. Copy file starting at number lines from end or beginning of file. with no options specified is equivalent to Options and Command-Line Arguments recognizes the following options and command-line arguments: Follow option. If the input file is a regular file or if file specifies a FIFO, do not terminate after the last line of the input file has been copied, but read and copy further bytes from the input file when they become available enters an end- less loop wherein it sleeps for one second then attempts to read and copy further records from the input file). This is useful when monitoring text being written to a file by another process. If no file argument is specified and the input is a pipe (FIFO), the option is ignored. number Decimal integer indicating quantity of output to be copied, measured in units specified by accompanying option. If number is preceded by a character, copy operation starts number units from beginning of file. If number is preceded by a character or the option name, copy operation starts number units from end of file. If number is not preceded by a or option, is assumed. If both the option and number are not specified, is assumed. Copy file beginning number 512-byte blocks from end or beginning of file. If number is not specified, is assumed. See number descrip- tion above. Copy file beginning number bytes from end or beginning of file. If number is not specified, is assumed. See number description above. Copy file beginning number lines from end or beginning of file. If number is not specified, is assumed. See number description above. file Name of file to be copied. If not specified, the standard input is used. If the option is specified, the input file can contain arbitrary data. Otherwise, the input file should be a text file. Obsolescent Form In the obsolescent form, option letters can be concatenated after the number argument to select blocks, bytes, or lines. If this syntax is used, must be the first argument given. If number is not specified, -10 is assumed. This version is provided for backward compatibility only. The forms discussed previously are recommended for portability. EXTERNAL INFLUENCES
Environment Variables determines the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments and input files). determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. However, the and options can break multi-byte characters and should be used with caution in a multi-byte locale environment. EXAMPLES
Print the last three lines in file to the standard output, and leave in ``follow'' mode: Print the last 15 bytes of file followed by any lines that are appended to after is initiated until it is killed: Three ways to print an entire file: WARNINGS
Various kinds of anomalous behavior may occur with character special files. For piped output, is limited in its output and depends on process limits. SEE ALSO
dd(1), head(1). STANDARDS CONFORMANCE
tail(1)
All times are GMT -4. The time now is 04:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy