help in splitting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help in splitting
# 1  
Old 05-27-2010
help in splitting

Hi experts,

In the lines below I am trying to copy only the words which come after "//" into an array

Code:
short nloh; // Comments
int age;    // Age of the person

Please help me in achieving this

After the code, the output of the array should
Code:
Comments
Age of the person

# 2  
Old 05-27-2010
Code:
echo "short nloh; // Comments" | awk -F "// " '{print $2}'

# 3  
Old 05-27-2010
Re:Help with splitting the line

Hi Devtakh, thanks for your quick reply. Can you please provide the solution in perl code?

Regards,
RB
# 4  
Old 05-27-2010
In unix:

Code:
#!/bin/ksh
i=0
while read line
do
array[$i]=`echo $line | awk -F "// " '{print $2}' `
#echo ${array[$i]}
i=`expr $i + 1 `
done < file4
echo ${#array[*]}
j=0
while [ $j -le ${#array[*]} ]
do
echo ${array[$j]}
j=`expr $j + 1`
done

# 5  
Old 05-27-2010
Re:Help with splitting the line

Thanks Devthak. But It will be very useful to me, if the code is written in perl.

Regards,
RB
# 6  
Old 05-27-2010
Code:
#!/usr/bin/perl
$data_file="file";
open(DAT, $data_file) || die("Could not open file!");

while ($line = <DAT>)
{
($f1,$f2)=split("// ",$line);
push(@array,$f2);
}
print @array;


Last edited by devtakh; 05-27-2010 at 07:19 AM.. Reason: tag
# 7  
Old 05-27-2010
Re:Help with splitting the line

Thanks, devtakh, it worked fine!

Regards,
Ramakanth
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 of file

Hi, I'm beginner in UNIX I would like to split file in separate files depending on Pattern. Input file looks like:-A B C brfbeg A B C brfbeg A B C brfbeg . . n so on (7 Replies)
Discussion started by: Rohit_Mokal
7 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 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

4. UNIX for Dummies Questions & Answers

Help with file splitting

Hey everyone, I would really appreciate some help with a problem I have filing away some data I have. I have multiple fasta files that have different pieces of information in each. I want to split each file into parts, and then file away each separate part into its own file. Here is an example... (8 Replies)
Discussion started by: Sneeketeeke
8 Replies

5. AIX

Splitting the File

Hello I have a requirement where i have to split the file into number of files. Lets say i have 200 records and i need to split the file with 50 records each which would be 4 files. If the file has 60 records then first 50 records in first file and then rest of the 10 records in second file. if... (3 Replies)
Discussion started by: dsdev_123
3 Replies

6. Shell Programming and Scripting

splitting the file

Hi , I have one file which has many headers. Say suppose HEDAER ..data DATA DATA ..data ..data HEADER ..data ..data DATA .data HEADER. ..data ..data If there are 3 HEADERS in source file then I need to split the source file into 3 separate file.... (2 Replies)
Discussion started by: tanyaheerani
2 Replies

7. UNIX for Dummies Questions & Answers

Help splitting file

hi, i was wondering how do i split a large text output file from a keyword, e.g. as soon as 'saveabc.dat' appears in the file. any answers would be much appreciated. thanks:confused: (3 Replies)
Discussion started by: shabs1985
3 Replies

8. UNIX for Dummies Questions & Answers

splitting the files

Hi, I have some files with 2 million odd records which i need to split into chunks of 0.5 millions. I have the file sorted with a key column in order. The same key value can appear as 4 or 5 records in the file. Hence after splitting we are checking whether all the key values are present in the... (5 Replies)
Discussion started by: dnat
5 Replies

9. 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

10. Shell Programming and Scripting

Need help in splitting the file

Hi, I got a file which may have 100 - 500 rows with header and trailer... based on the total number of real rows ( excluding header and trailer) I want to break the file in 3 or 4 files .. Coded like this .. but giving error in the AWK in 8th line of below code. awk 'NR > 5 {print line}... (3 Replies)
Discussion started by: Vaddadi
3 Replies
Login or Register to Ask a Question