Sponsored Content
Top Forums Shell Programming and Scripting awk/grep copy and paste and insert in between lines. Post 302335236 by the1hand3r on Friday 17th of July 2009 06:55:39 PM
Old 07-17-2009
awk/grep copy and paste and insert in between lines.

Hi all,

I'm a unix newb andI'm trying to write a script that can copy some text paste it in a certian place and then add a number. It's not really clear but I'll show an example.

what the file looks like right now:

Code:
Linux 2.6.24-24-generic (abc)       07/15/09

23:25:01        CPU     %user     %nice   %system   %iowait    %steal     %idle
23:35:01        all      1.33      0.00      0.08      0.00      0.00     98.59
23:45:01        all      1.36      0.00      0.08      0.00      0.00     98.56
23:55:01        all      1.33      0.00      0.08      0.00      0.00     98.58
23:59:01        all      1.59      0.00      0.09      0.00      0.00     98.32
00:00:01        all      1.50      0.00      0.12      0.00      0.00     98.32
00:05:01        all      1.49      0.00      0.12      0.14      0.00     98.25
00:15:01        all      1.33      0.00      0.07      0.00      0.00     98.60
00:25:01        all      1.44      0.00      0.07      0.00      0.00     98.49
00:35:01        all      1.26      0.00      0.07      0.00      0.00     98.66
00:45:01        all      1.37      0.00      0.09      0.00      0.00     98.53

Desired output:

Code:
Linux 2.6.24-24-generic (abc)       07/15/09
23:25:01        CPU     %user     %nice   %system   %iowait    %steal     %idle
23:35:01        all      1.33      0.00      0.08      0.00      0.00     98.59
23:45:01        all      1.36      0.00      0.08      0.00      0.00     98.56
23:55:01        all      1.33      0.00      0.08      0.00      0.00     98.58
23:59:01        all      1.59      0.00      0.09      0.00      0.00     98.32
Linux 2.6.24-24-generic (abc)       07/16/09
00:05:01        all      1.49      0.00      0.12      0.14      0.00     98.25
00:15:01        all      1.33      0.00      0.07      0.00      0.00     98.60
00:25:01        all      1.44      0.00      0.07      0.00      0.00     98.49
00:35:01        all      1.26      0.00      0.07      0.00      0.00     98.66
00:45:01        all      1.37      0.00      0.09      0.00      0.00     98.53

As you can see the first line of the txt file was copied and inserted between 23:59:01 and 00:05:01 with the date changed to 07/16/09. I'm thinking something along the lines of adding one using awk could solve this problem? I'm not sure, but basically i can use any utility including but not limited to awk, sed, perl to do this.

Thanks so much unix community,
the1hand3r.

Last edited by vgersh99; 07-17-2009 at 09:01 PM.. Reason: code tags, PLEASE!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut Paste and Insert Help

Hello I have a very large file where say each line is made up of 80 characters. I want to cut the characters from 20-30 and 50-60 from each line and then insert a delimiter between them (# or | etc). eg input file 000000000131.12.20990000590425246363375670011200140406... (5 Replies)
Discussion started by: PradeepRed
5 Replies

2. Shell Programming and Scripting

sed/awk script selective insert between lines

Hi I have a file in the foll. format *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD AV* Data *FIELD RF* *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD RF* (4 Replies)
Discussion started by: dunstonrocks
4 Replies

3. UNIX for Dummies Questions & Answers

copy and paste certain many lines of huge file in linux

Dear All, I am working with windoes OS but remote a linux machine. I wonder the way to copy an paste some part of a huge file in linux machine. the contain of file like as follow: ... dump annealling all custom 10 anneal_*.dat id type x y z q timestep 0.02 run 200000 Memory... (2 Replies)
Discussion started by: ariesto
2 Replies

4. Shell Programming and Scripting

copy/paste with awk

Hi everybody, I have two XML files. I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file. Here is my first XML file. This is the second XML file. Finaly, I wnat to obtain something like that : ... (2 Replies)
Discussion started by: lsaas
2 Replies

5. Shell Programming and Scripting

sed/awk to insert multiple lines before pattern

I'm attempting to insert multiple lines before a line matching a given search pattern. These lines are generated in a separate function and can either be piped in as stdout or read from a temporary file. I've been able to insert the lines from a file after the pattern using: sed -i '/pattern/... (2 Replies)
Discussion started by: zksailor534
2 Replies

6. Shell Programming and Scripting

Using a combination of sort/cut/grep/awk/join/paste/sed

I have a file and need to only select users that have a shell of “/bin/bash” in the line using awk or sed please help (4 Replies)
Discussion started by: boyboy1212
4 Replies

7. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 12.4 1.72849432773174e+01 -7.74784188610632e+01 12.5 9.59432114416327e-01 -7.87018212757537e+01 15.6 5.20139995965960e-01 -5.61612429666624e+01 29.3 3.76696387248366e+00 -7.42896194101892e+01 32.1 1.86899877018077e+01 -7.56508762501408e+01 35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies

8. Shell Programming and Scripting

awk to insert duplicated lines

Dear All, Suppose I have a file: 1 1 1 1 2 2 2 2 3 3 3 3I want to insert new line under each old line so that the file would become: 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3How can this be accomplished using awk (or sed)? (5 Replies)
Discussion started by: littlewenwen
5 Replies

9. UNIX for Dummies Questions & Answers

Copy Lines between Keywords & paste them to another file

hi, I have Multiple files with the following data : File1 100414 DR1 END XXXXX Test1 Test2 Test3 Test4 Test5 Test6 END 100514 DR2 END XXXXX Test7 Test8 Test9 Test10 Test11 Test12 END 100614 DR3 (5 Replies)
Discussion started by: newageBATMAN
5 Replies

10. Shell Programming and Scripting

Use sed/awk to do like copy and paste

I have rrd file which is have the gaps and I want to fill it out with some value , I've got 10 NaN record and I try to populate data from 10 records be for NaN to change instead of NaN :( <!-- 2016-05-19 14:10:00 CST / 1463638200 -->... (11 Replies)
Discussion started by: boobytrap
11 Replies
PASTE(1)						    BSD General Commands Manual 						  PASTE(1)

NAME
paste -- merge corresponding or subsequent lines of files SYNOPSIS
paste [-s] [-d list] file ... DESCRIPTION
The paste utility concatenates the corresponding lines of the given input files, replacing all but the last file's newline characters with a single tab character, and writes the resulting lines to standard output. If end-of-file is reached on an input file while other input files still contain data, the file is treated as if it were an endless source of empty lines. The options are as follows: -d list Use one or more of the provided characters to replace the newline characters instead of the default tab. The characters in list are used circularly, i.e., when list is exhausted the first character from list is reused. This continues until a line from the last input file (in default operation) or the last line in each file (using the -s option) is displayed, at which time paste begins selecting characters from the beginning of list again. The following special characters can also be used in list: newline character tab character \ backslash character Empty string (not a null character). Any other character preceded by a backslash is equivalent to the character itself. -s Concatenate all of the lines of each separate input file in command line order. The newline character of every line except the last line in each input file is replaced with the tab character, unless otherwise specified by the -d option. If '-' is specified for one or more of the input files, the standard input is used; standard input is read one line at a time, circularly, for each instance of '-'. EXIT STATUS
The paste utility exits 0 on success, and >0 if an error occurs. EXAMPLES
List the files in the current directory in three columns: ls | paste - - - Combine pairs of lines from a file into single lines: paste -s -d ' ' myfile Number the lines in a file, similar to nl(1): sed = myfile | paste -s -d ' ' - - Create a colon-separated list of directories named bin, suitable for use in the PATH environment variable: find / -name bin -type d | paste -s -d : - SEE ALSO
cut(1), lam(1) STANDARDS
The paste utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. HISTORY
A paste command appeared in Version 32V AT&T UNIX. BSD
June 25, 2004 BSD
All times are GMT -4. The time now is 10:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy