awk split single column into multiple columns based on RS
Hello,
I have a .csv file full of device configurations, listed in a single column. Each configuration starts with the word "version". I would like to split each configuration off and put them all in another file, one config in each column. I found a solution that puts each configuration in its own file here, using Code:
awk '{print $0 "version"> "file" NR}' RS='version' input-file Thanks in advance. |
Please, could you post a sample of the input file? Have the different configurations the same number of items (lines)?
|
1 Attachment(s)
Quote:
|
Looking at your sample file, I'm not sure about the desired output. Here is an awk code that takes the various configurations and put them side by side (independently from their length) using a fixed column width (previously computed):
Code:
BEGIN { Finally note that I had to do some conversions to the sample file in order to avoid unpredictable results: I converted it from UTF-16 to UTF-8 encoding and changed the Windows-style line terminators (CR+LF) to Unix-style (LF): Code:
$ iconv -fUTF-16 -tUTF-8 sample-csv.txt > sample.csv |
Quote:
i would split the file by each line that contains version then paste each file together. (you mite need to work on space padding each line to the length that you want) |
Quote:
How do you append file contents to a new column in a an existing csv file (when the number of files is unknown and their lengths are different)? Example: |Column A | Column B | Column C |contents of file 1 | contents of file 2 | contents of file 3 |
^ what i mentioned above is that your input is just plain unformatted ascii text (not sure why you think it is in csv format: http://en.wikipedia.org/wiki/Comma-separated_values ).
edit: i found this via google for splitting the input: Code:
awk '{print "version"$0 > "config-"++i".txt"}' RS="version" largefile.csv |
Quote:
|
I agree with schneidz re: not being a .csv file - are you sure you uploaded the right one?
Code:
[joshua:/tmp o]$ iconv -fUTF-16 -tUTF-8 sample-csv.txt > sample.csv |
^ you still misunderstand although its not that important to your issue.
regardless of the filename, the content inside your file is not in csv format (i.e.: the open-office csv import funtion doesnt separate it out into columns correctly because the file isnt separated by comma according to the value of each feild). |
Quote:
|
csplit can achieve it in a similar way:
Code:
$ csplit sample.csv '%^" *version%' '/^" *version/' '{*}' |
All times are GMT -5. The time now is 08:22 PM. |