![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help required with a Csh script to read data from a file | fizzme | Shell Programming and Scripting | 1 | 05-29-2008 08:30 PM |
| Need to read data from a file (cut/awk) | rejirajraghav | Shell Programming and Scripting | 1 | 04-29-2008 04:13 PM |
| Post Shell programming: Question about source a file and read data from the file | ccwq | Shell Programming and Scripting | 3 | 08-04-2007 11:28 PM |
| Read from data file | fongthai | Shell Programming and Scripting | 12 | 02-27-2007 09:22 PM |
| Read data from a file into a variable | yorkdg | Shell Programming and Scripting | 2 | 12-09-2004 05:29 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Read data from one file and putting in new file ??
Hello All,
I have a file which contain data something like this: CELL 2 TEST AND DIAGNOSTIC UNIT 2 CELL 2, CDM 1 CBR 1 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 2 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 1 CELL 2, CDM 1 CBR 1 TRANSMIT PORT (TXPORT) 2 CELL 2, CDM 1 CBR 2 TRANSMIT PORT (TXPORT) 2 CELL 2, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 2 CELL 3 PACKET PIPE (PP) 3 CELL 3, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 1 CELL 4 TIME FREQUENCY UNIT (TFU) 1 CELL 4 TEST AND DIAGNOSTIC UNIT 2 CELL 4, CDM 1 PRIMARY SIGNALING LINK CELL 4, CDM 1 ALTERNATE SIGNALING LINK CELL 4 PACKET PIPE (PP) 1 CELL 4 PACKET PIPE (PP) 2 CELL 4 PACKET PIPE (PP) 3 What i want is that i read that file and those lines which starts from cell 2 copies and paste into new file named cell2 in the same directory, same as for cell 2 and cell 3 and 4. Its mean that 3 new files will be created named cell2,cell3 & cell4. Any idea how i can do this ?? Regards, Waqas Ahmed |
|
||||
|
Hi, the following script reads in the file line by line, then extracts the filenumber from string, constructs the corresponding filename and prints the matching information to this file. Blank lines are delete. Code:
while read line
do
[[ $line = *CELL* ]] \
&& FILENUMBER=$(sed 's/CELL \([0-9]\+\)[ ,].*/\1/' <<< $line) \
&& echo $line >> cell${FILENUMBER}
done < file
HTH Chris |
|
||||
|
Hello All,
I used this : cat cell | grep "CELL 2" > cell2 to read file named cell and to grep only lines that starts from cell 2. But when i open the output file cell2 so it also contain lines starting from cell 21 22 23 to 29. But my requirement is that output file cell2 only contains lines that starts from cell 2 not from cell21 to 29. I hope you understand what i am saying. How i can do that? Regards, Waqas Ahmed |
|
||||
|
Hi, firstly: you don't need cat: grep "pattern" file is enough. secondly: your regexp search for all patterns matching "CALL 2" at "any position of any length". Code:
grep "^CELL 2[ ,]" file Will match only lines starting with "CELL" followed by "2" and a space or comma. Try my solutions. It should give you what you want. Save it in a file a make it executable or run it from the command line. |
|
||||
|
Hello Christoph Spohr Can you please tell me the usage procedure of your code: Code:
while read line
do
[[ $line = *CELL* ]] \
&& FILENUMBER=$(sed 's/CELL \([0-9]\+\)[ ,].*/\1/' <<< $line) \
&& echo $line >> cell${FILENUMBER}
done < file
where i have to put the filename which will be read. i save your code and make it executable but its giving below error: KarachiOMP root> ./co ./co: syntax error at line 6: `FILENUMBER=$' unexpected |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|