![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare multiple fields in file1 to file2 and print line and next line | gillesc_mac | Shell Programming and Scripting | 7 | 03-16-2009 06:26 AM |
| Reading a file line by line and processing for each line | sagarparadkar | Shell Programming and Scripting | 6 | 03-02-2009 11:59 AM |
| cat file1 read line-per-line then grep -A 15 lines down in fileb | irongeekio | Shell Programming and Scripting | 6 | 01-28-2009 06:30 AM |
| I need suggestion on problem read a file line by line and do stuff | madi3d8 | Shell Programming and Scripting | 3 | 01-15-2009 11:33 AM |
| SED help (remove line::parse again::add line) | Malumake | Shell Programming and Scripting | 6 | 10-24-2007 05:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||||
|
You can do this many way, but here is one example how to use parameter expansion.
Code:
#!/bin/ksh
# read lines from stdin
while read line
do
# remove begin of line including <html>
a1=${line#*<html>}
# remove end of line including </html>
a2=${a1%</html>*}
# remove all char except numbers (replace not numbers with nothing)
a3=${a2//[^0-9]/}
print $a3
done
Code:
chmod a+x thisfile cat file1 | ./thisfile > file2 |
|
|||||
|
in summary.. SEE Below
In file1, line 1 (<html>...unique identifier23432..</html>) needs to be > to the identifier in line 1 in file2 (creating a NEW file name for each record)(23432).html (creating new file based on unique identifier) ---------- Post updated at 08:51 AM ---------- Previous update was at 08:36 AM ---------- #!/bin/ksh #create counter cnt=0 # read lines from stdin while read line do # remove begin of line including <html> a1=${line#*<html>} # remove end of line including </html> a2=${a1%</html>*} # remove all char except numbers (replace not numbers with nothing) a3=${a2//[^0-9]/} print $a3 #increment cnt for testing creation of new unique identifier cnt=$(($cnt+1)) done > $cnt.html $ksh test3.ksh test3.ksh[17]: : bad substitution $ This 1 file is created: 0 Jun 28 08:41 0.html blank and no 1,2, 3 and so forth.. Any other ideas? Quote:
in summary.. SEE Below In file1, line 1 (<html>...unique identifier23432..</html>) needs to be > to the identifier in line 1 in file2 (creating a NEW file name for each record)(23432).html (creating new file based on unique identifier) ---------- Post updated at 08:51 AM ---------- Previous update was at 08:36 AM ---------- #!/bin/ksh #create counter cnt=0 # read lines from stdin while read line do # remove begin of line including <html> a1=${line#*<html>} # remove end of line including </html> a2=${a1%</html>*} # remove all char except numbers (replace not numbers with nothing) a3=${a2//[^0-9]/} print $a3 #increment cnt for testing creation of new unique identifier cnt=$(($cnt+1)) done > $cnt.html $ksh test3.ksh test3.ksh[17]: : bad substitution $ This 1 file is created: 0 Jun 28 08:41 0.html blank and no 1,2, 3 and so forth.. Any other ideas? Quote:
---------- Post updated at 11:40 AM ---------- Previous update was at 08:51 AM ---------- Thank you but unfortunately, this will not create what I need.. |
|
|||||
|
I'm not sure what you are trying, sort input file example and what you like to be result example.
Code:
while ...
do
# a3 is the key value, look first example script
> $a3.html
done
Code:
cnt=1
while read line
do
# create/overwrite empty file using some variable value
> $cnt.html
# or put something to file
print something > $cnt.html
((cnt+=1))
done
|
|
|||||
|
Input file dfn and Output file(s) dfn
My input file is a list of html code for products that have a unique key as their id numbers in the description of the code..
test1 <html>(the code for product #####)</html> <==a complete webpage i wanted to use the cnt value to represent a unique means of createing a new and different file fore each line in he test1 file so in essenct, it is creating a new html file for each line which I have tested and verified is seperated by a carrage return and no tabs or carage returns in the line itself. filename.txt is another possible input file i tried to used a mv script to change the name of the cnt.html files created by the first script |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| parse lines onto new file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|