Need separate vi files in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need separate vi files in shell
# 1  
Old 11-13-2015
Need separate vi files in shell

Input:

I have input file below mentioned.Input file has Yahoo,gmail,yuimn etc..are websites and there are users listed under it. I have many other unique websites but i mentioned just few as below.

For example: Yahoo is website and 123,fsfd are members of website "yahoo". See below input file.All websites,users are in one column.

Code:
more input.txt

Yahoo
        123
        fsfd
        
        
Gmail
        10022000
        100dfg018
Yuimn
        dfsdfsd
        dfdsfdsfds

Output:

Code:
Output:

Need each wesite in separate text file with users listed on it as below.

vi yahoo

123
fsfd

vi gmail

10022000
100dfg018

vi Yuimn
    
dfsdfsd
dfdsfdsfds

# 2  
Old 11-13-2015
Code:
awk '
        NF && !/^ / {
                ofile = $1
                next
        }
        NF && /^ / {
                print $1 >> ofile
                close(ofile)
        }
' input.txt

This User Gave Thanks to Yoda For This Post:
# 3  
Old 11-13-2015
Hi Yoda,

i have executed script and it has written nothing.
# 4  
Old 11-13-2015
Did you check the working directory you ran this awk program and verified that there are no output files?

If there are no output files, can you run below command and post the output:-
Code:
od -c input.txt | head -10

This User Gave Thanks to Yoda For This Post:
# 5  
Old 11-13-2015
Just for fun, place ^I with literal tab....

Code:
(sed  -e '/^[ ^I]*$/d' -e '1s/^\([^ ^I].*\)/ cat >"\1" <<EOF/' -e '2,$s/^\([^ ^I].*\)/cat >"\1" <<EOF/' -e '/^cat/i\EOF' -e 's/^[ ^I]*//' input.txt;echo 'EOF') | sh

This User Gave Thanks to cjcox For This Post:
# 6  
Old 11-13-2015
Hi Yodha,

Yes there are no output files. and i ran command you have provided and below is output:

Code:
sample]$ od -c sample.out | head -10

0000000   M   S   D   A   R   G  \n  \t   a   l   e   g  \n  \t   c   l
0000020   i   n   i   c   a  \n  \t   E   D   U   B   O   S   S   I  \n
0000040  \t   m   a   r   i   o  \n  \t   t   i   g   r   e   c   a   r
0000060  \n   M   S   D   B   R   Z  \n  \t   1   0   0   0   0   0  \n
0000100  \t   1   0   0   0   1   8  \n  \t   1   0   0   0   3   4  \n
0000120  \t   1   0   0   1   3   2  \n  \t   1   0   0   1   5   8  \n
0000140  \t   1   0   0   1   8   6  \n  \t   1   0   0   1   9   7  \n
0000160  \t   1   0   0   2   1   6  \n  \t   1   0   0   2   2   7  \n
0000200  \t   1   0   0   2   6   5  \n  \t   1   0   0   2   7   9  \n
0000220  \t   1   0   0   2   8   0  \n  \t   1   0   0   3   1   0  \n

---------- Post updated at 12:11 PM ---------- Previous update was at 12:09 PM ----------

Hi Cjcox

i ahve run command you posted. It has created files for each users,thats not expected. It has created almost 1 million files
# 7  
Old 11-13-2015
Your file is <TAB> delimited, whic you didn't specify nor include in your sample . Try this adaption of Yoda's script (and try it on a small subset of your data):
Code:
awk '!/^    / {OFN=$1; next} {print > OFN}' file
cf M*
MSDARG:
    aleg
    clinica
    EDUBOSSI
    mario
    tigrecar
MSDBRZ:
    100000
    100018
    100034
    100132
    100158
    100186
    100197
    100216
    100227
.
.
.

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar with variable date in separate shell

Hi, I am trying to Zip a folder inside a shell script like below. It successfully taring but it only returns Null inside the variables. Searched a lot but no clue to finding the root cause. testno=1; date=20171128; DIR=/root/ sh -c 'cd $DIR; tar cvf "AWS.${testno.${date}.tar" "./AWS"' ... (5 Replies)
Discussion started by: pradyumnajpn10
5 Replies

2. Shell Programming and Scripting

Output in separate files

Hi all, i have the bash script for remote conection, for hosts in $(cat /list); do ssh user1@$hosts "hostname"; done execute hostname command by all hosts and show standar ouput, how i can send to file by each host in lists, so e.g. $cat list 10.0.0.1 10.0.0.2... (1 Reply)
Discussion started by: aav1307
1 Replies

3. UNIX for Dummies Questions & Answers

Intersect of two columns in two separate files

Hi, I have a file like this: abc def ghi jkl mno My second file is like this (tab delimited): adsad sdfsdf dfdf wads abc dfdsf sdsf jkl sfsdf dsfds sdfd reor zxczd dsf sff Now, I want the code to report the lines (from file2) which have common strings in column 2 with the first... (4 Replies)
Discussion started by: a_bahreini
4 Replies

4. Web Development

Two separate domains - and files

Hi, I've been asked to 'troubleshoot' a webserver where two different TLDs are being served. Or to be more accurate, 'domain.com' and 'domain.fr'. So we have /var/www/domain.com /var/www/domain.fr And then for some reason, the httpd.conf file points to two different configuration files.... (1 Reply)
Discussion started by: davidm123SED
1 Replies

5. Shell Programming and Scripting

Using bash to separate files files based on parts of a filename

Hey guys, Sorry for the basic question but I have a lot of files that I want to separate into groups based on filenames which I can then cat together. Eg I have: (a_b_c.txt) WB34_2_SLA8.txt WB34_1_SLA8.txt WB34_1_DB10.txt WB34_2_DB10.txt WB34_1_SLA8.txt WB34_2_SLA8.txt 77_1_SLA8.txt... (1 Reply)
Discussion started by: Breentax
1 Replies

6. Shell Programming and Scripting

Comparing columns in two separate files

Hey all, I have a file structure that looks something like this: file1 306708278 88954535 234167885 file2 2012-03-27T12:32:56+00:00 137 Orchotorena 184616310003601409 306708278 es 40.4777947 Majadahonda -3.6416896333333333 0 false atlante83 "<a href=""http://tapbots.com/tweetbot""... (8 Replies)
Discussion started by: dgaff
8 Replies

7. Shell Programming and Scripting

Need help with shell, trying to append or separate values in a string

Ok. I for the life of me cant figure out how to do this. I need Help. So here is what I'm trying to do. I have a block of text. They are FIPS codes for counties. Below is the block. There are probably a few ways to do this. The first line starting with ARC021....... this line is a list of... (2 Replies)
Discussion started by: chagan02
2 Replies

8. Shell Programming and Scripting

Separating Pattern Into Separate Files

I am trying to separate a specific pattern match into separate files. Sometimes there is only one pattern match, but other times there could be multiple (up to 6 or 8). Pattern is as follows - its starts with NYZ or VTZ and ends with $$. Again looking to get those blocks of data from one big... (17 Replies)
Discussion started by: Double-E
17 Replies

9. Shell Programming and Scripting

Separate String Shell Script

Hi guys, I am a beginner in shell script.. How can I separate a string coming from a parameter in spaces ? Ex: input: test.sh abcd output: a b c d Thanks Dusse (15 Replies)
Discussion started by: dusse
15 Replies

10. Shell Programming and Scripting

Break a file into separate files

Hello I am facing a scenario where I have a file with XML content and I am running shell script over it. But the problem is the XML is getting updated with new services. In the below scenario, my script takes values from the xml file from one service name say ABCD. Since there are multiple, it is... (8 Replies)
Discussion started by: chiru_h
8 Replies
Login or Register to Ask a Question