Printint characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printint characters
# 1  
Old 08-08-2016
Printint characters

hi ,
how can i print every character in new line on unix
i want to have abcd like this:
Code:
a
b
c
d

this code didn't worked in my os but worked on linux
Code:
echo "abcd"|  'sed 's/\(.\)/\1\n/g'

best reagard


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-08-2016 at 05:38 AM.. Reason: Added CODE tags.
# 2  
Old 08-08-2016
Wouldn't you think, too, that it helped if you told us WHAT your OS is on which that code didn't work? And, what your shell is, because that might offer an easy answer/solution as well...
# 3  
Old 08-08-2016
UnixWare 7.1.4 and shell is csh
# 4  
Old 08-08-2016
Quote:
Originally Posted by rezasadeghi
hi ,
how can i print every character in new line on unix
i want to have abcd like this:
Code:
a
b
c
d

this code didn't worked in my os but worked on linux
Code:
echo "abcd"|  'sed 's/\(.\)/\1\n/g'

best reagard
Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
Hello rezasadeghi,

Please use code tags as per forum rules for your Input_file/code/commands which you are using into your code. Following is the rules link for same, you could go through it once.
https://www.unix.com/misc.php?do=cfrules

Coming to your requirement, could you please try following and let us know then.
Code:
awk '{A=A?A OFS $0:$0} END{print A}'  Input_file

NOTE: As per your Input_file only above command is provided, in case you have other requirements by which above output is not matching to your requirements, then please mention all the details about your requirements along with sample Input_file and expected output too, along with your O.S details etc.

Thanks,
R. Singh
# 5  
Old 08-08-2016
my requirements :
print "abcd" like :
a
b
c
d
the solution of you didn't work
# 6  
Old 08-08-2016
Showing us the exact diagnostics produced by your code when it doesn't work ALWAYS helps get a meaningful answer sooner.

Removing the extraneous unmatched single quote would probably help. Depending on what operating system and version of sed you're using, that might even fix your problem. But, probably not on UnixWare.

Try:
Code:
echo "abcd"|sed 's/./&\
/g'

where there is nothing but a <newline> character following the backslash at the end of the 1st line.

NOTE: With the extra single quote before sed in your script I can't believe that that worked on any system. I will not guarantee that the above will work with csh and its derivatives, but it should work with any shell based on Bourne shell syntax.

Last edited by Don Cragun; 08-08-2016 at 05:58 AM.. Reason: Add note.
# 7  
Old 08-08-2016
Quote:
Originally Posted by rezasadeghi
my requirements :
print "abcd" like :
a
b
c
d
the solution of you didn't work
Hello rezasadeghi,

Sorry for that, didn't understand problem correctly. Following may help you in same.
Code:
 awk '{num=split($0, A,"");for(i=1;i<=num;i++){print A[i]}}'  Input_file

Also I have tried above command in GNU awk in BASH.

Thanks,
R. Singh
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

Remove first 2 characters and last two characters of each line

here's what im trying to do. i have a file containing lines similar to this: data.txt: 1hsRmRsbHRiSFZNTTA1dlEyMWFkbU5wUW5CSlIyeDFTVU5SYjJOSFRuWmpia0ZuWXpKV2FHTnRU 1lKUnpWMldrZFZaMG95V25oYQpSelEyWTBka2QyRklhSHBrUjA1b1kwUkJkd3BOVXpWM1lVaG5k... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

Get all last 4 characters of files

Hi All. Seeking for your assistance to get all the last 4 characters of each file before "." and put it in the variable ex. abcdZWU1501.csv abcdXYZ1501.csv abcdEFG1502.csv abcdHIJ1501.csv output will be: 1501 1502 What i did was (6 Replies)
Discussion started by: znesotomayor
6 Replies

4. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

5. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

6. Shell Programming and Scripting

Cut the last 15 characters off

Hi Gurus, I am trying to execute the below command. However the output shows the value + path of the folder where the command is being executed. But I am only interested in the value but not the path. du -hs /aps/inf/SeLogs when I execute the above command, output is 32G... (5 Replies)
Discussion started by: svajhala
5 Replies

7. Shell Programming and Scripting

How to replace characters with random characters

I've got a file (numbers.txt) filled with numbers and I want to replace each one of those numbers with a new random number between 0 and 9. This is my script so far: #!/bin/bash rand=$(($RANDOM % 9)) sed -i s//$rand/g numbers.txtThe problem that I have is that it replaces each number with just... (2 Replies)
Discussion started by: hellocatfood
2 Replies

8. UNIX for Dummies Questions & Answers

How to remove Characters before '~'

Hi, I am having a file which contains records as follows: DETAIL_KEY~12344|ACTIVE_PASSIVE~Y|AVG_SIZE_OF_RESPONSE~123123131 DETAIL_KEY~12344|ACTIVE_PASSIVE~Y|AVG_SIZE_OF_RESPONSE~123123131 DETAIL_KEY~12344|ACTIVE_PASSIVE~Y|AVG_SIZE_OF_RESPONSE~123123131... (4 Replies)
Discussion started by: Amey Joshi
4 Replies

9. Shell Programming and Scripting

characters ô ö à é è

Hi! I have a file with some characters with accent. I don't find the solution to translate ô ö as o à as a é è as e ç as c With the command tr or sed? I can't write sed 's/ô/o/g' because the copy/paste ô don't work. Thanks! (1 Reply)
Discussion started by: Castelior
1 Replies

10. Shell Programming and Scripting

Contol M (^M) characters

Is there a way to recursively find scripts/files with ^M characters embedded in them Usually the case is when a file is saved on unix but in dos/windows format it ends up have ^M characters at the end of each line. Please let me know if there is a way to recursively find them. (3 Replies)
Discussion started by: Anubhav
3 Replies
Login or Register to Ask a Question