Append by line number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append by line number
# 8  
Old 09-14-2017
Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

With the description and the data given, this
Code:
paste -d" " file[12]
jump over

will do what was requested.
# 9  
Old 09-14-2017
Why can't you use paste? It should be a standard Linux command.

This sed script may work with the caveat that I don't guarantee all lines will be pasted (should one file be longer than the other):

Code:
printf "%s\n" {a..z} > rightfile
printf "%s\n" {1..26} > leftfile
< rightfile sed 's/\^/\\^/g'  | sed '=;s!^!s^$^ !;s!$!^!'  | sed 'N;s/\n/\t/' > tmpfile
< leftfile sed -f tmpfile
1 a
2 b
3 c
4 d
5 e
6 f
7 g
8 h
9 i
10 j
11 k
12 l
13 m
14 n
15 o
16 p
17 q
18 r
19 s
20 t
21 u
22 v
23 w
24 x
25 y
26 z

I've written it so you can type
Code:
< file

and then paste the rest of the line from the first sed.

It's horrible but it works on my Ubuntu system.

Andrew

Last edited by apmcd47; 09-14-2017 at 10:10 AM.. Reason: clarification about why I I don't guarantee all lines will be pasted
# 10  
Old 09-14-2017
Quote:
Originally Posted by RudiC
Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

With the description and the data given, this
Code:
paste -d" " file[12]
jump over

will do what was requested.
hi
i cant see how i can ask any different way
i think i made it clear enough

no it wont do what i want as the txt is always different

in post one

i would to do this by line number as the txt is always different
# 11  
Old 09-14-2017
No, you didn't make it clear at all, as you can see by the number of people wildly guessing around what the problem is. Why would the paste proposal NOT fulfill your needs, even when "txt is always different"?
You posted the contents of file1 to be one single word, you didn't bother to post an example of file2; the desired output lets conclude it has one single word as well. Will that always be the case?
Why do you need "to do this by line number" - in post#1 it has been defined to be line 1 from file1 to go to the begin of file 2, i.e. line 1. You don't seem to see your requirements clearly yourself...?

Last edited by RudiC; 09-14-2017 at 01:29 PM..
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Need append sequence number

Hi, Need to add sequnce number to one of the csv file and please find below actual requirement. Input file ABC,500 XXQ,700 ADF,400, ART,200 Out put file should be 1,ABC,500 2,XXQ,700 3,ADF,400, 4,ART,200 (3 Replies)
Discussion started by: siva83
3 Replies

3. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

4. Shell Programming and Scripting

Write $line number into textfile and read from line number

Hello everyone, I don't really know anything about scripting, but I have to manage to make this script, out of necessity. #!/bin/bash while read -r line; do #I'm reading from a big wordlist instructions using $line done Is there a way to automatically write the $line number the script... (4 Replies)
Discussion started by: bobylapointe
4 Replies

5. Shell Programming and Scripting

append out on particular line number

I want to append output of below command to a file name "final" mentioned on line number 9. sed 's/peter/xyz/g' ttc >> final (7 Replies)
Discussion started by: learnbash
7 Replies

6. 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

7. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

8. Shell Programming and Scripting

Joining lines in reverse. append line 1 to line 2.

Hi I have used many times the various methods to append two lines together in a file. This time I want to append the 1st line to the second and repeat for the complete file.... an example This is the file owns the big brown dog joe owns the small black dog jim What I want is ... (7 Replies)
Discussion started by: dwalley
7 Replies

9. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies

10. Shell Programming and Scripting

Appending line number to each line and getting total number of lines

Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me. I have a file say: abc def ccc ddd ffff The output should be: Instance1=abc Instance2=def Instance3=ccc Instance4=ddd Instance5=ffff ... (2 Replies)
Discussion started by: chiru_h
2 Replies
Login or Register to Ask a Question