- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Parsing the dreaded backslash
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
Discussions
Discussions
Forums
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
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
тАО11-10-2004 07:38 AM
тАО11-10-2004 07:38 AM
UserName,FullName,AccountType,Comment,HomeDrive,HomeDir,Profile,LogonScript, etc...
The problem is the HomeDir field. It often contains backslashes, such as \\servername\share. The problem is that the \ character screws up the parse.
For example:
cat windowspasswd.work | while read line
do
username=`echo $line | awk -F, '{print $1}'`
fullname=`echo $line | awk -F, '{print $2}'`
pwdlastchanged=`echo $line | awk -F, '{print $11}'`
pwdlifetime=`echo $line | awk -F, '{print $16}'`
disabled=`echo $line | awk -F, '{print $15}'`
pwdexpires=`echo $line | awk -F, '{print $13}'`
.
.
.
I get username and fullname correctly, but after that they all come up blank.
Oddly, when I run the echo $line | awk commands from the command line, they DO work. But they don't in the script. I know it's the backslashes, because if I blank out the HomeDir field, the line is parsed fine.
Running:
cat users.xls | grep 44SSFAC,
Shows:
44SSFAC,44 Simon St. Facilities,User,#037919 see Lou Guerci,H:,\\cadillac\44ssfaC$,,login.bat,,No ,etc...
Note the double \\ in front of Cadillac -- as it should be.
Running:
line=`cat users.xls | grep 44SSFAC,`; echo $line
Shows:
44SSFAC,44 Simon St. Facilities,User,#037919 see Lou Guerci,H:,\cadillac\44ssfaC$,,login.bat,,No ,etc...
Note the single \ in front of "Cadillac".
This is only to highlight that $line isn't receiving the proper value of the field. It's interpretting the \, and causing issues.
And I don't for the life of me understand why the echo $line | awk commands work from the command line, but fail in the script.
Any ideas? I don't care about the \ at all, nor the field it's in. But it's screwing up the parse and I want it out of the picture.
Thanks.
Solved! Go to Solution.
- Tags:
- csv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2004 07:48 AM
тАО11-10-2004 07:48 AM
Re: Parsing the dreaded backslash
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2004 07:49 AM
тАО11-10-2004 07:49 AM
SolutionOne way to do it would be to use 'tr' to delete all the '\' characters in your input. Something like this might work:
tr -d '\\'
username=`echo $line | awk -F, '{print $1}'`
fullname=`echo $line | awk -F, '{print $2}'`
pwdlastchanged=`echo $line | awk -F, '{print $11}'
...
JP
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2004 08:16 AM
тАО11-10-2004 08:16 AM
Re: Parsing the dreaded backslash
perl -ne 'chomp;@a=split(",");print join(",",@a[0,1,10,15,14,12]),"\n";' users.xls
This will split each record at "," then rejoin just the field you are interested in.
HTH
-- Rod Hills
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-10-2004 11:00 AM
тАО11-10-2004 11:00 AM
Re: Parsing the dreaded backslash
cat windowspasswd.work |
awk -F"," '{
printf("%s %s %s %s %s %s\n",$1,$2,$11,$16,$15,$13);
}' |
while read username fullname pwdlastchanged pwdlifetime disabled pwdexpires
do
...
done
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2004 07:21 AM
тАО11-12-2004 07:21 AM
Re: Parsing the dreaded backslash
print -r worked, but I need to port the script to Solaris... which doesn't recognize "print". :-/
The tr -d '\\'
Sorry, the solution has to work in the bourne shell. Perl wasn't an option.
I couldn't get the
cat windowspasswd.work |
awk -F"," '{
printf("%s %s %s %s %s %s\n",$1,$2,$11,$16,$15,$13);
Thing to work right. It ran and it ran much faster, but it seemed to be interpreting the spaces as well as commas as field seperators. I played around with it, but couldn't get it work properly.
Thanks again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-12-2004 08:12 AM
тАО11-12-2004 08:12 AM
Re: Parsing the dreaded backslash
Bill Hassell, sysadmin
- Tags:
- quoting