LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2017, 12:30 AM   #1
end
Member
 
Registered: Aug 2016
Posts: 266

Rep: Reputation: Disabled
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.
 
Old 08-30-2017, 12:56 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Perhaps you haven't read the sed manpage closely enough. It usually suffices.
 
1 members found this post helpful.
Old 08-30-2017, 01:19 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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'
 
1 members found this post helpful.
Old 08-30-2017, 02:17 AM   #4
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-30-2017, 02:30 AM   #5
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by end View Post
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?
 
1 members found this post helpful.
Old 08-30-2017, 02:50 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Code:
sed -i.bak 's;keyword="old";keyword="new";' somefile.ext
 
2 members found this post helpful.
Old 08-30-2017, 04:45 AM   #7
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 08-30-2017, 05:34 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
That will be very surprising:
Code:
sed -i.bak 's;keyword="";keyword="new";' somefile.ext
 
1 members found this post helpful.
Old 08-30-2017, 05:52 AM   #9
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
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

Last edited by end; 08-30-2017 at 06:00 AM.
 
Old 08-30-2017, 05:58 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by end View Post
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.
 
1 members found this post helpful.
Old 08-30-2017, 06:23 AM   #11
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-30-2017, 06:33 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
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
 
1 members found this post helpful.
Old 08-30-2017, 06:44 AM   #13
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
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.

Last edited by end; 08-30-2017 at 06:46 AM.
 
1 members found this post helpful.
Old 08-30-2017, 07:12 AM   #14
end
Member
 
Registered: Aug 2016
Posts: 266

Original Poster
Rep: Reputation: Disabled
it was something with my browser about rate post
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make menuconfig: saves a larger file then original after save done when no changes made. Devyn Linux - Software 6 04-15-2016 03:40 PM
[SOLVED] Manipulate text file to allow import to excel dimothy Linux - Software 3 06-14-2010 07:50 AM
Remove lines in text file that contain two '@' symbols xsyntax Linux - Newbie 5 12-07-2009 05:58 PM
text match pipe to file then delete from original text file create new dir automatic tr1px Linux - Newbie 6 09-10-2008 09:40 PM
how to import users in qmail from text file Braytac Linux - Software 5 12-24-2006 09:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration