I am very new to Unix and using sed so I'm struggling a little bit with this command and was hoping someone could help me out.
I want to find a nested pattern in a file and replace some text in that file with text from another file.
For example, in file one I have something like this:
In my file two all I have is a new set of Huffy models:
which I want to put into file one, replacing what was originally being returned if myBike == "Huffy" under bikeModels to get a file that looks like this:
I can use sed to find the chunk of the file I want with a command like:
sed -n '/bikeModels/,/^$/ {myBike == "Huffy"/,/]/p}; file1
but I have no idea how to replace that text with the text from file two.
I did see I could use:
sed -e '/regex/{r insert.file' -e 'd;}' source
but, again, I have no idea how to combine everything I want to do and have it work.
Thanks to anyone that can help. Let me know if I need to go into more detail or explain anything better.
Thanks, it's close but it's replacing the Huffy information in both bikeModels and bikeColors. I just want to replace that information in whichever one I specify, in this case bikeModels. I've only used awk for very basic stuff but I'll play around with it for a little while and see if I have better luck than I have had with sed.
Sorry to bump this up but the hurricane meant I wasn't able to check the forums for a few days. Just wondering if anyone else maybe had some insight as to how to go about solving my problem whether it's through sed or awk. Thanks.
Thanks so much for replying everyone.
I'm trying to use this command as one line without much luck (I keep getting the message "sed: -e expression #1, char 22: extra characters after command" no matter how I try to reformat the command).
I am entering the command as one line as follows:
sed '/def bikeModels/ { N /Huffy/ { H n /return/ { x r file2 d} } }' file1
Like I said in my post, I am EXTREMELY new to this and kind of got thrown into having to write this command so I'm trying to figure things out on the fly. Should I be able to one line it like that or am I totally doing something wrong? I have tried to move things around/remove spaces in the command but keep getting the same message but with different locations i.e. character 27.
I have a file like below.
2018.07.01, Sunday
09:27 some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday
09:31 some text 123456789 1 41 0.26 0.32 0.00
09:39 some text 456789012 1 0.07 0.09 0.09
09:45 some text 932469494 1 55 0.29 0.36 0.00
16:49 some text 123456789 0 48 0.12 0.15 0.00... (9 Replies)
The intended result should be :
PDF converters
'empty line'
gpdftext and pdftotext?xml version="1.0"?>
xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters
gpdftext and pdftotext</note-content>... (9 Replies)
Hi,
I get the following response by gphoto2 and I would like to substract the index number of the current item. In this case 3.
gphoto2 --get-config /main/imgsettings/iso
Label: ISO Speed
Type: RADIO
Current: 200
Choice: 0 100
Choice: 1 125
Choice: 2 160
Choice: 3 200
Choice: 4 250
..... (11 Replies)
Hi ,
I have a file where i have modifed certain things compared to original file . The difference of the original file and modified file is as follows.
# diff mir_lex.c.modified mir_lex.c.orig
3209c3209
< if(yy_current_buffer -> yy_is_our_buffer == 0) {
---
>... (5 Replies)
'Hi
I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match.
Which option is to be used to exclude the line containing the pattern?
sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Hi,
I have two files file1.txt and file2.txt. Please see the attachments.
In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
1. The problem statement, all variables and given/known data:
I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested.
The input-file is:
aaa { bbb ccc { ddd eee } fff { ... (2 Replies)
Ok, this one isn't for everybody, it's pretty tough and I've spent a good deal of time on it without figuring it out yet.
Can anybody get this script to work:
#!/bin/bash
cq_fname="%let outputfile="/user/cq_"$1".csv";"
sed "29s/.*/\"$cq_fname\"/" file1.sas >... (3 Replies)
Here's the input:
alpha, numeric or alphanumeric string ("line 1 string")
numeric string ("line 2 string")
numeric string ("line 3 string")
numeric string ("line 4 string")
...
where
- each numeric string is in a pattern that can be matched with RE but
- there can be any number of... (2 Replies)
This is my first post, please be nice. I have tried to google and read different tutorials.
The task at hand is:
Input file input.txt (example)
abc123defhij-E-1234jslo
456ujs-W-abXjklp
From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)