- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- problem with shell script - reading folder
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:21 AM
06-15-2006 12:21 AM
I have a strange problem with my shell script..I have in folder meny txt and doc files I am only interested in txt files..how can I read certan data from each file and write it back to one file..
any ideas?
I have like 300 txt files in one folder and there is in each file peace of info that I need each file has this structure:
mysql -u
THIS LINE IS TARGET
so basicly I only need last line from txt file..tail -1 is target value..
any ideas or start code??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:28 AM
06-15-2006 12:28 AM
Re: problem with shell script - reading folder
do
tail -1 $a >> newfile
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:35 AM
06-15-2006 12:35 AM
Re: problem with shell script - reading folder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 12:38 AM
06-15-2006 12:38 AM
Re: problem with shell script - reading folder
for FILE in `ls`; do
if tail -1 $FILE|grep ^mysql >> /dev/null; then
tail -1 $FILE >> ouputfile
fi
done
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 02:02 AM
06-15-2006 02:02 AM
Re: problem with shell script - reading folder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 03:45 AM
06-15-2006 03:45 AM
Re: problem with shell script - reading folder
grep 'mysql -u' *.txt > accum.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 05:59 PM
06-15-2006 05:59 PM
Re: problem with shell script - reading folder
I figure it out..but now I have anothe small problem..
I have this:
awk '{printf("INSERT INTO akcije (date, time, target1, target, action) VALUES ('%s','%s','%s','%s','%s');\n",substr($0,0,6),substr($0,8,17),substr($0,25,8),substr($0,33,6),substr($0,48,11));}' ca > CAndA.sq
result is: from CAndA.sq file:
..
...
INSERT INTO akcije (date, time, target1, target, action) VALUES (20060524,145222,5431,876,west);
...
.
which is not good command for mysql it needs to be like this:
INSERT INTO akcije (date, time, target1, target, action) VALUES ('20060524','145222','5431','876','west');
how can I show those ''...
I also tryed with \' insted just ' but same result..any ideas?
Thanks..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 08:09 PM
06-15-2006 08:09 PM
Re: problem with shell script - reading folder
try
awk '{printf("INSERT INTO akcije (date, time, target1, target, action) VALUES ('%s','%s','%s','%s','%s');\n",substr($0,0,6),substr($0,8,17),substr($0,25,8),substr($0,3
3,6),substr($0,48,11));}' ca |sed s/\'//g > CAndA.sq
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 08:35 PM
06-15-2006 08:35 PM
Re: problem with shell script - reading folder
same with this sed as without sed..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 09:08 PM
06-15-2006 09:08 PM
Re: problem with shell script - reading folder
try to put the
"'"'"'"
before and after the substr function:
awk '{printf("INSERT INTO akcije (date, time, target1, target, action) VALUES ('%s','%s','%s','%s','%s');\n","'"'"'"substr($0,0,6)"'"'"'","'"'"'"substr($0,8,17)"'"'"'","'"'"'"substr($0,25,8)"'"'"'","'"'"'"substr($0,3
3,6)"'"'"'","'"'"'"substr($0,48,11)"'"'"'");}' ca > CAndA.sq
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 09:12 PM
06-15-2006 09:12 PM
Re: problem with shell script - reading folder
in my test it work:
awk '{print "'"'"'"substr($2,2,5)"'"'"'","'"'"'"substr($2,2,5)"'"'"'"}' test
'prova' 'prova'
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 09:21 PM
06-15-2006 09:21 PM
Re: problem with shell script - reading folder
Cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2006 09:29 PM
06-15-2006 09:29 PM
Re: problem with shell script - reading folder
http://www.gnu.org/software/gawk/manual/html_node/Quoting.html
Here there is many example more readable than that I gave you for single quote in awk.
Enrico