LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   import text beatwen symbols and save as original file (https://www.linuxquestions.org/questions/programming-9/import-text-beatwen-symbols-and-save-as-original-file-4175612888/)

end 08-30-2017 12:30 AM

import text beatwen symbols and save as original file
 
hi

im writing script for installing arch linux. so after installing system [pacstrap] some config files need to modify and bootloader config. i whant that include in script. i try with sed but sed doesent save original file it creates another modyfy file with imported text. so what metod to use if i whant import text beatwenn "" -symbols and save original file without creating another file.

syg00 08-30-2017 12:56 AM

Perhaps you haven't read the sed manpage closely enough. It usually suffices.

NevemTeve 08-30-2017 01:19 AM

It would be a fair challenge, if you knew for sure OP reads English well enough. Otherwise it could be better to explicitly mention option '-i'

end 08-30-2017 02:17 AM

thanks

actualy im following book linux command line and bible. and examples that use i option is with echo text examples, and modify file after inport text is have to save as different file. and deffinitly my english. and if you have time hove to sepify lets say to import beatwen symbol in line.

in text file lets say i have Some Text="" , and i whant to import text beatwen quotation marks.

Turbocapitalist 08-30-2017 02:30 AM

Quote:

Originally Posted by end (Post 5753587)
in text file lets say i have Some Text="" , and i whant to import text beatwen quotation marks.

sed is a little terse and so is the reference manual. But that also means it is simple once you get it. Try checking "man sed" on your system as you progress. Also see these guides:

Then you can try some sed program like the following:

Code:

sed -e '/Some Text/!d; s/^[^"]*"//; s/"[^"]*$//;' inputfile.txt > outputfile.txt
Can you say in more detail what you mean by importing the text between the quotes? Where do you want the text to end up, in a shell variable, a file, or somewhere else?

NevemTeve 08-30-2017 02:50 AM

Code:

sed -i.bak 's;keyword="old";keyword="new";' somefile.ext

end 08-30-2017 04:45 AM

i whant import in file in this case.

Code:

sed -i.bak 's;keyword="old";keyword="new";' somefile.ext
exacly this.

last two days im going throught book and writing evry example and now i see i dont think very much. its not that hard but thousunt things to combine i think i sleept half of book and i red first half.

and one more thing im boring i know, but same example some text="" but when beatween quotation marks there is no words or letters.

NevemTeve 08-30-2017 05:34 AM

That will be very surprising:
Code:

sed -i.bak 's;keyword="";keyword="new";' somefile.ext

end 08-30-2017 05:52 AM

yes but doesent work i try already somehove all command seems to work evry fifth time something strange.

but i found now my self basic solution i dont know way i didnt try before maybe all reading scare me about sed.

sed -i 's/""/"sometext"/' file.txt

or if need specify directory

sed -i 's/""/"some:\/"/' file.txt

thanks for help prichiated now sed is cool

Turbocapitalist 08-30-2017 05:58 AM

Quote:

Originally Posted by end (Post 5753638)
sed -i 's/""/"sometext"/' file.txt

That will replace all the empty quotes in the whole file with the same string, though only one per line.

Also, it is a very good idea to add a suffice for -i to use. Without a suffix, sed will overwrite the existing file and you'll have no automatic backup copy. If you have a suffix on -i then you get a backup copy automatically with the suffix as an added extension.

Maybe you can show a few lines that you want to change and then show how you would like them to look after processing.

end 08-30-2017 06:23 AM

you can look in grub file /etc/default/grub, on arch is at fifth line

GRUB_CMDLINE_LINUX=""

i whant to look

GRUB_CMDLINE_LINUX="crypt=/dev/sdaX:cryptroot"

can i put in sed that affect only fifth line of file he will not delete all other content.

NevemTeve 08-30-2017 06:33 AM

Kindly do exactly what your are told, not just something similar...
Code:

sed -i.bak 's;GRUB_CMDLINE_LINUX="";GRUB_CMDLINE_LINUX="crypt=/dev/sdaX:cryptroot";' /etc/default/grub

end 08-30-2017 06:44 AM

yes you are right it workink.

thanks both for help it realy help a lot to simplify this to me, and good base for rest of book.

and way i cant click post helpfull it say you need to have at least one post to rate post.

end 08-30-2017 07:12 AM

it was something with my browser about rate post


All times are GMT -5. The time now is 05:55 AM.