Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, I attempted to separate the text output by some software into array, but I can't find any pattern or function, I tried cut with space, but doesn't seem to work, partly because I can't find the position:
Code:
| . DR 0 Mon Nov 7 02:05:42 2011|
| .. DR 0 Mon Nov 7 02:05:42 2011|
| 12.05.08.rtf A 2890 Mon May 12 01:31:43 2008|
| 7[1][1].3CHCH annoying shit.txt A 616 Mon Nov 27 07:19:18 2006|
| app_online_en.pdf A 2176553 Mon Jun 2 19:54:15 2008|
| Course Enrollment Form.pdf A 69019 Fri Sep 15 23:51:23 2006|
| Criterion Games D 0 Tue Aug 30 20:18:59 2011|
| CyberLink D 0 Sat Jul 17 13:51:33 2010|
| Dear Admission administrators.doc A 24576 Tue May 20 09:19:54 2008|
| Default.rdp AH 0 Fri Nov 7 22:52:12 2008|
| desktop.ini AHS 556 Fri Aug 26 20:37:00 2011|
Each line is divided by "|" and "|" at the end, the elements are filename, attribute, size and date.
For example, i tried: FILENAME=$(echo "$dir1" | cut -d' ' -f1), but i got a blank string.
Thanks,
Ted
I copy/pasted your sample data into a file named stuff.
Code:
$ gawk 'BEGIN {RS = "[|]?\n?[|]"}; {filename = $1; attribute = $2; size = $3; date = $4 " " $5 " " $6 " " $7 " " $8; print filename, attribute, size, date}' stuff
. DR 0 Mon Nov 7 02:05:42 2011
.. DR 0 Mon Nov 7 02:05:42 2011
12.05.08.rtf A 2890 Mon May 12 01:31:43 2008
7[1][1].3CHCH annoying shit.txt A 616 Mon Nov 27
app_online_en.pdf A 2176553 Mon Jun 2 19:54:15 2008
Course Enrollment Form.pdf A 69019 Fri Sep 15
Criterion Games D 0 Tue Aug 30 20:18:59
CyberLink D 0 Sat Jul 17 13:51:33 2010
Dear Admission administrators.doc A 24576 Tue May 20
Default.rdp AH 0 Fri Nov 7 22:52:12 2008
desktop.ini AHS 556 Fri Aug 26 20:37:00 2011
I think that's what you want, but there are many ways this program can break. For example, if the file was generated on Windows the line endings will be different, breaking my record separator regex.
Thanks,
but how would i go about printing them out in html form instead of saving them?
That wasn't asked for in your original post. I get the idea that there is a much larger shell script we need to see from you. The program I provided should not be considered robust or reliable without some testing.
If this were my project, I would seriously consider doing it entirely in Gawk.
You can simply include the HTML codes as arguments in Gawk's print statement. String literals should be enclosed in double quotes. If you need to include double quotes in a string literal you can backslash escape them.
hi, sorry for the misunderstanding, I am using smbclient to fetch folder directories from a windows computer, I believe this is the only circumstance that I will be using this code for. This code will appear on a webpage cgi-bin, folder. And the output will show up on the web page like a default directory browser for any webbrowser:
Code:
OUT="$(smbclient \\\\My-Computer\\'My Documents' -N >&1 <<SMB
ls
SMB)"
IFS="
"
##here i have just fetched the directory listing, and the response text is divided into array separted by an "enter" via IFS
dir=($OUT)
i=0
for dir1 in $dir[@} ; do
if [$i -ge 1 ] ; then
array=$(echo "$stuff" | gawk 'BEGIN {RS = "[|]?\n?[|]"}; {filename = $1; attribute = $2; size = $3; date = $4 " " $5 " " $6 " " $7 " " $8;}')
echo -n "<tr><td><a><img src=\"../style/fex/$EXT.png\" /></a></td>
<td style=\"width:270px\"><a><font color=\"black\">$filename</font></a></td>
<td>$attribute</td><td>$size</td>
<td>$date<img style=\"cursor:pointer; width:15px; height:15px;\" src=\"$IMG\" /></a>"
echo -n "</td></tr>"
fi
i=$(($i+1))
done
## here I skipped the first line because the first line of the smbclient shows up something like [Windows 7] [Workgroup] [my computer]...etc, so it starts from the second line.
Please let me know if it is still unclear.
Thanks,
Ted
sh-3.1# smbclient "\\\\TED-PC\\My Documents" -N
Domain=[TED-PC] OS=[Windows 7 Professional 7600] Server=[Windows 7 Professional 6.1]
smb: \> ls
. DR 0 Mon Nov 7 02:05:42 2011
.. DR 0 Mon Nov 7 02:05:42 2011
12.05.08.rtf A 2890 Mon May 12 01:31:43 2008
7[1][1].3CHCH annoying shit.txt A 616 Mon Nov 27 07:19:18 2006
app_online_en.pdf A 2176553 Mon Jun 2 19:54:15 2008
Course Enrollment Form.pdf A 69019 Fri Sep 15 23:51:23 2006
Criterion Games D 0 Tue Aug 30 20:18:59 2011
hi, sorry for the misunderstanding, I am using smbclient to fetch folder directories from a windows computer, I believe this is the only circumstance that I will be using this code for. This code will appear on a webpage cgi-bin, folder. And the output will show up on the web page like a default directory browser for any webbrowser:
No. Just no. There ought to be an apache module for this functionality.
I'm sorry, but in light of this new information I don't feel qualified to help you find an adequate solution. If the Gawk program is helpful to you then I'm glad.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.