Splitting with bash...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting with bash...
# 1  
Old 04-18-2013
Splitting with bash...

hello there,

i've tried to format a dump-file to the right format.

Here is how the source look like:
Code:
sometext:1102:F761943D471AA8183C5A42D81E4E281B:72E2A45309E15DE1E58F1A6D4FA666B7:::
someother:1108:183C5A42D81E4E2F761943D471AA881B:E1E58F1A72E2A45309E15D6D4FA666B7:::

so the first thing i did is
Code:
cat textfile.txt |cut -d: -f4 >textfile2.txt

after that, it looks like this
Code:
72E2A45309E15DE1E58F1A6D4FA666B7
E1E58F1A72E2A45309E15D6D4FA666B7

now my question: i need to cut this exact in the middle after 16 characters,
the file should look like this then (for each
Code:
72E2A45309E15DE1
E58F1A6D4FA666B7
E1E58F1A72E2A453
09E15D6D4FA666B7

and i have no idea how to do this.

any ideas?

regards

muelli

Last edited by jim mcnamara; 04-18-2013 at 07:56 AM..
# 2  
Old 04-18-2013
Hi
try to add this awk:
Code:
cat textfile.txt |cut -d: -f4 |awk '{ printf "%s\n%s\n",substr($1,1,16),substr($1,17);}'>textfile2.txt

In a single command:
Code:
awk -F: '{ printf "%s\n%s\n",substr($4,1,16),substr($4,17);}' textfile.txt >textfile2.txt


Last edited by franzpizzo; 04-18-2013 at 07:49 AM..
# 3  
Old 04-18-2013
Code:
cut -c1-16

# 4  
Old 04-18-2013
Code:
#! /bin/bash
while IFS=':' read a b c req e
do
    echo ${req:0:16}
    echo ${req:16}
done < file

# 5  
Old 04-18-2013
Code:
cut -d: -f4 | fold -w16

If there's a chance that fa carriage return, backspace, or tab character can appear in the 4th field, you'll want to use fold's -b option.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with splitting fields

Hi. I want to put the first field to the end and the lines are of different number of fields. How should I do this with awk? Thanks. (3 Replies)
Discussion started by: dustinwang2003
3 Replies

2. Shell Programming and Scripting

Splitting columns

Hi Friends, My input file has more than 20 columns UniProtKB A0A183 LCE6A GO:0031424 GO_REF:0000037 IEA UniProtKB-KW:KW-0417 P Late cornified envelope protein 6A LCE6A_HUMAN|C1orf44|LCE6A protein taxon:9606 20120303 UniProtKB ... (9 Replies)
Discussion started by: jacobs.smith
9 Replies

3. Shell Programming and Scripting

Splitting files

Hello all I have a file which has around 80 million records, I want to split it to 12 equal files, I tried using the split command but it is allowing me to split according to number of lines or by size. Is there a way i can split the file into 12 files without worrying about the number of lines... (7 Replies)
Discussion started by: Sri3001
7 Replies

4. Shell Programming and Scripting

splitting value

Hello, i want to take a one word from my file. -- myfile.txt -- test blablabla suPHP_ConfigPath /home/performe/etc blablabla etc. bla bla. -- myfile.txt -- How can i take performe from this file ? Thank you. (7 Replies)
Discussion started by: SAYGIN
7 Replies

5. Shell Programming and Scripting

help in splitting

Hi experts, In the lines below I am trying to copy only the words which come after "//" into an array short nloh; // Comments int age; // Age of the person Please help me in achieving this After the code, the output of the array should Comments Age of the person (6 Replies)
Discussion started by: ramakanth_burra
6 Replies

6. Shell Programming and Scripting

help splitting a file into multiple files in bash

I have a file that logs multiple sessions. What I would like to do is split this file inclusive of the lines that include "starting session" and "shutting down" and ignore the data before and after the beginning of the first session and the end of the last session. The output files can be called... (2 Replies)
Discussion started by: elinenbe
2 Replies

7. Shell Programming and Scripting

splitting a file

I have a huge file with 13 million records , how do i split this file into 13 files which has 1 million records in each ( each record is one line) I tried this but how to print the second million etc cat file | head -1000000 > file1 cat file | tail -1000000 >file13 please shed some... (1 Reply)
Discussion started by: ramky79
1 Replies

8. Shell Programming and Scripting

splitting the files

Hi, I'am using HP-UX.I have a input file which has 102 drop statements in it.I'am using csplit to split the files.The upper limit is 99 only.I'am using the -n 102 option.It says "suffix size not vaild".Any suggestions how to do it using csplit? Thanx in advance, sounder. (1 Reply)
Discussion started by: sounder123
1 Replies

9. Shell Programming and Scripting

file splitting

I have an ebcdic file of 8gig into multiple chunks using the following script split -b 1024m 04122004.BIG.txt RMS the first file RMSaa looks fine. But in the second file RMSab, the first letter starts at 9th byte instead of 1st byte and therfore it chopps everynting else that falls... (1 Reply)
Discussion started by: rintingtong
1 Replies

10. UNIX for Dummies Questions & Answers

splitting strings

Hi you, I have the following problem: I have a string like the followings: '166Mhz' or '128MB' or '300sec' or ... What I want to do is, I want to split the strings in a part with the numbers and a part with letters. Since the strings are not allway three digits and than text i couldn't do... (3 Replies)
Discussion started by: bensky
3 Replies
Login or Register to Ask a Question