Replace line for another line in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace line for another line in file
# 1  
Old 12-31-2017
Replace line for another line in file

Hey,

i have been struggeling to find the answer myself so this is the best forum
has alwyas help me Smilie

i have an API that get data from a provider via curl.
the data comes like this :

Code:
AccountCode1234 CompneyNameA Credit: 200
AccountCode5678 CompneyNameB Credit: 200
AccountCode999 CompneyNameC Credit: 200
AccountCode2312 CompneyNameD Credit: 200
AccountCode555 CompneyNameE Credit: 200

as i dont have control of how the data present itself, and only to widraw it
i need some line to be changes heads on with other line

for exsample that thw row:
AccountCode1234 CompneyNameA Credit: 200
will be replaced with the row :
AccountCode2312 CompneyNameD Credit: 200

so the data in the file will show this order :
Code:
AccountCode2312 CompneyNameD Credit: 200
AccountCode5678 CompneyNameB Credit: 200
AccountCode999 CompneyNameC Credit: 200
AccountCode1234 CompneyNameA Credit: 200
AccountCode555 CompneyNameE Credit: 200

an not like the first exsample.
i have find info on how to chage but it deleteing the other row.
i dont wanna lose rows i just want to replace thir order.

thanks


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-31-2017 at 07:28 AM.. Reason: Added CODE tags.
# 2  
Old 12-31-2017
Please show your attempts. And, how does your code know which lines to swap?
# 3  
Old 12-31-2017
Hey,

my attemps were with sed
sed 's/origline/changedline/g'

but its not what im looking for,
the only thing i can maybe do is a while read line
and give every line a number. but i tought maybe somone here knows better :\

thanks
# 4  
Old 12-31-2017
That leaves RudiC's other question:
Quote:
Originally Posted by RudiC
[..]And, how does your code know which lines to swap?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

4. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

5. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

6. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

Hi I am not the best scripter in the world and have run into a issue which you might be able to guide me on... I have two files. File1 : A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB File2: C345,... (5 Replies)
Discussion started by: luckycharm
5 Replies

7. Shell Programming and Scripting

sed to replace a line with modified line in same file

i have few lines in a file... i am reading them in a while loop so a particular line is held is $line1.. consider a modified line is held in $line2.... i want to replace $line1 with $line2 in the same file... how to do it..? i have come up till the below code sed "s/$line1/$line2/g" tmpfile.sql... (5 Replies)
Discussion started by: vivek d r
5 Replies

8. Solaris

Line too long error Replace string with new line line character

I get a file which has all its content in a single row. The file contains xml data containing 3000 records, but all in a single row, making it difficult for Unix to Process the file. I decided to insert a new line character at all occurrences of a particular string in this file (say replacing... (4 Replies)
Discussion started by: ducati
4 Replies

9. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

10. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies
Login or Register to Ask a Question