LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-04-2012, 10:49 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Rep: Reputation: 0
Unhappy how to have a single quotes around a string


I have a text file which has nos
say

cat tempfile
123536
171718
8716390-303363
727287


I want the format output and change it to
'123536',
'171718',
'8716390-303363',
'727287'

Can anybody help me please !

Thanks million

Last edited by sysmicuser; 10-04-2012 at 10:55 PM.
 
Old 10-04-2012, 10:53 PM   #2
sackboy
LQ Newbie
 
Registered: Sep 2012
Posts: 20

Rep: Reputation: Disabled
Hi,

There's lots of ways to do this, here's one:
for line in `cat tempfile`; do echo "\'$line\'"; done
 
1 members found this post helpful.
Old 10-05-2012, 12:25 AM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 619

Rep: Reputation: 42
this seems like homework, just read up on "sed" it will teach you how to do it.
 
Old 10-05-2012, 01:20 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
So long as the file isn't ridiculously large, I'd do it in vi/vim
 
Old 02-13-2013, 09:26 PM   #5
sysmicuser
Member
 
Registered: Mar 2010
Posts: 334

Original Poster
Rep: Reputation: 0
chirsm01

How would do it with vim. I know that in vim "." would repeat the last operation but here we are doing the '898282', so it involves 3 operations, I am just trying to understand if there is any better approach to solve the problem.
 
Old 02-13-2013, 11:04 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Actually, in the general case, the previous answers are better.
I was just offering an option for changing the content of the file, rather than the output.
Depends on exactly what you want.

vim cmds
Code:
#all start of line => ' (insert)
:%s/^/'/

#all end of line => ',  (append)
:%s/$/',/
You'd just manually delete last ','

Actually, for the latter, you can specify the line range (specify start & end line nums) to edit, thus avoiding last comma.
Code:
:1,3s/$/',/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 04:03 PM
[SOLVED] Printing single quotes with awk caspernoome Linux - Newbie 3 07-27-2011 11:30 AM
Python - string to omit the single quotes (') linuxuser111 Programming 1 03-18-2011 07:42 PM
Variables within single quotes are not evaluated? Akhran Linux - Newbie 1 03-10-2006 09:32 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 12:41 PM


All times are GMT -5. The time now is 10:11 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration