insert multiple characters in string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers insert multiple characters in string
# 1  
Old 05-06-2012
insert multiple characters in string

Hello, newb here Smilie

How do I add square brackets before and after the first character in a string using sed?

e.g.
Code:
0123456
[0]123456

My attempts have been fruitless.

Code:
sed 's/.\{0\}/[/;s/.\{1\}/]/'

Thanks.

Last edited by Scrutinizer; 05-06-2012 at 11:20 AM.. Reason: code tags
# 2  
Old 05-06-2012
Hi, try
Code:
sed 's/./[&]/'

-or-
Code:
s=0123456
echo "[${s%${s#?}}]${s#?}"

# 3  
Old 05-06-2012
Perfect, thank you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies

3. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

4. Shell Programming and Scripting

Find a string and then return the next 20 characters in multiple files

Hello all, I have a directory with 2000+ files. I need to look in each file for an invoice number. To identify this, i can search for the string 'BIG' and then retrieve the next 30 characters. I was thinking awk for this, but not sure how to do it. Each file contains one long string and in... (8 Replies)
Discussion started by: jdinero
8 Replies

5. Shell Programming and Scripting

Korn shell to insert cyrillic characters into the databse

i have written a shell script that reads a csv file and inserts tokenized strings into the database. the problem comes when the csv file has cyrillic characters. how do i set the parameters in my shell script(korn shell) so that any characters can be inserted into the database. (3 Replies)
Discussion started by: vkca
3 Replies

6. Shell Programming and Scripting

insert spaces between characters with pure shell

A file contains: abcdef I need : a b c d e f It's easy with sed sed 's/./& /g'but this is embedded linux that doesn't have sed/awk. The shell is unknown but it's bashlike. Parameter expansion works and seems promising and. A question mark seems to work as a wildcard, but there doesn't seem... (5 Replies)
Discussion started by: fubaya
5 Replies

7. Shell Programming and Scripting

remove characters from string based on occurrence of a string

Hello Folks.. I need your help .. here the example of my problem..i know its easy..i don't all the commands in unix to do this especiallly sed...here my string.. dwc2_dfg_ajja_dfhhj_vw_dec2_dfgh_dwq desired output is.. dwc2_dfg_ajja_dfhhj it's a simple task with tail... (5 Replies)
Discussion started by: victor369
5 Replies

8. Shell Programming and Scripting

Insert space between characters using sed

Input: Youcaneasilydothisbyhighlightingyourcode. Putting space after three characters. You can eas ily dot his byh igh lig hti ngy our cod e. How can i do this using sed? (10 Replies)
Discussion started by: cola
10 Replies

9. Shell Programming and Scripting

How to insert greek characters in to vi editor

Hi, I want to test a unix file by inserting greek characters in to vi editor. Can anyone please suggest how to insert greek characters in to vi editor. (2 Replies)
Discussion started by: DSDexter
2 Replies

10. Programming

how to insert and delete characters in the middle of file

I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
Login or Register to Ask a Question