Seperating one word into columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Seperating one word into columns
# 1  
Old 02-15-2008
Seperating one word into columns

Hi,

Our issue is that we want to separate a string of characters, like

xyxyxyxxxxyyxyxy

into a column,
x
y
x
y
...

I'm sure there's an easy awk fix for this, but being inexperienced, I figured I would ask on here.

Thanks a lot in advance!
# 2  
Old 02-15-2008
Code:
echo "xyxyxyxxxxyyxyxy" | \
awk ' {
       for(i=1; i<=length($0); i++) {print substr($0,i,1)} 
       }'

# 3  
Old 02-15-2008
Okie dokie,

Now all I have to do is to figure out how to use that to pick our line out of our files and go. And that shouldn't be too terribly hard. Thanks a million!

~NovaGhostii
# 4  
Old 02-15-2008
Code:
# echo "xyxyxyxxxxyyxyxy" | awk 'BEGIN{FS=""}{for (i=1;i<=NF;i++)print $i}'

or
Code:
echo "xyxyxyxxxxyyxyxy" | awk 'BEGIN{FS="";OFS="\n"}{$1=$1}1'


Last edited by ghostdog74; 02-16-2008 at 09:46 PM..
# 5  
Old 02-16-2008
A SED one
Code:
$ echo "xyxyxyxxxxyyxyxy" | sed -e 's/[a-z]/& \n/g'

//Jadu
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

Find a word and increment the number in the word & save into new files

Hi All, I am looking for a perl/awk/sed command to auto-increment the numbers line in file, P1.tcl: run_build_model sparc_ifu_dec run_drc set_faults -model path_delay -atpg_effectiveness -fault_coverage add_delay_paths P1 set_atpg -abort_limit 1000 run_atpg -ndetects 1000 I would like... (6 Replies)
Discussion started by: jypark22
6 Replies

3. UNIX for Dummies Questions & Answers

Match columns and write specific word

Hi all I have another question as of now. I have two files One file contain data like this Serendipity glamerus Shenpurity In another file these entries are present in different columns like this from 2 column onwards SRN Serendipity Non serendipity ... (1 Reply)
Discussion started by: Priyanka Chopra
1 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

6. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

7. UNIX for Dummies Questions & Answers

seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file. I want to seperate the records which has the field 1=(any of the number from numbers... (15 Replies)
Discussion started by: Shiv@jad
15 Replies

8. Shell Programming and Scripting

seperating the words from a line??

The line is like this +abc+def+mgh+ddsdsd+sa i.e. words seperated by +. There is a plus in the beginning. i want to conver this line to abc, def, mgh, ddsdsd, sa please provide the logic in the form of a shell script Thanks in advance (3 Replies)
Discussion started by: skyineyes
3 Replies

9. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

10. UNIX for Dummies Questions & Answers

Seperating Files

I wonder if there is any method that can effectively cut a file into 2 or more files... with the title on top... like this Original File : TITLE 1 001 ABC 002 DEF 003 GHI 004 JKL into 4 file : File 1: TITLE 1 001 ABC File 2: (6 Replies)
Discussion started by: biglemon
6 Replies
Login or Register to Ask a Question