LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09:49 PM   #1
sysmicuser
Member
 
Registered: Mar 2010
Posts: 458

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 09:55 PM.
 
Old 10-04-2012, 09: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-04-2012, 11:25 PM   #3
cbtshare
Member
 
Registered: Jul 2009
Posts: 645

Rep: Reputation: 42
this seems like homework, just read up on "sed" it will teach you how to do it.
 
Old 10-05-2012, 12:20 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

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

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, 10:04 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:59 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
Open Source Consulting | Domain Registration