awk filelist containing strange characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk filelist containing strange characters
# 1  
Old 08-31-2011
awk filelist containing strange characters

I've written a script:

Code:
find -depth | awk ‘
   {
      if ( substr($1,length($0)-2,3) == “/1.” )
         { print $1 }
         { system(“awk -f test1.awk “ $1 ) }
   }
‘

The idea is that it trundles through a large directory structure looking for files which are named '1.' and then passes them to an awk script which processes them. However, the directory structure has some unusual folders which are tripping it up. These folders have the caret (^) and commas (,) in their names, for example:

INBOX^Year2011
Details for Sue, Bob, Jane

I think with those sorts of folder names you have to enclose everything in double quotes, but I'm not sure how to do that in the above script. I've tried playing around with variables, and /" and suchlike, but I'm not sure if it's even possible. My scripts are displaying errors such as 'Cannot open.... no such file or directory...' The {print $1} line seems to work - it displays the full path to the file.

Thanks.
# 2  
Old 08-31-2011
Careful, whatever word processor you're using to edit your text is substituting odd characters for ' and ".

You could put some of that processing work into find and make your awk script redundant, allowing find to flawlessly feed filenames into awk for you. No special quoting is necessary this way.

Code:
find -depth -type f -name '1.' -print -exec echo awk -f test1.awk '{}' ';'

The -name makes it find files named exactly "1.", -print makes it print the name to stdout first, then -exec runs your awk script on the file -- or would if the echo wasn't there.

Remove the 'echo' once you've tested that it does exactly what you want.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 08-31-2011
Thanks very much for that - I'll give it a whirl.

I just re-typed the script into Word on my PC so that I could post it here - the original was created using vi on my Unix server.
# 4  
Old 08-31-2011
I suggest typing into either the window the web page provides, or notepad, not just here but on any technical forum. Word does many untoward substitutions beyond the ones I've noted that would mess up a script and make it difficult to deduce what the code actually was.

Last edited by Corona688; 08-31-2011 at 02:44 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Strange behaviour in AIX

Can someone please explain the strange behaviour.. I was just trying a few things to learn awk.. in the below code when I start the braces in the same line, the output is as expected, when I start at next line, output is displayed twice. Please see the file, code I tried and output below. ... (2 Replies)
Discussion started by: Kulasekar
2 Replies

2. Programming

Strange characters in FORTRAN code output

Hi guys, After compiling a .f90 code and executing it, i get strange characters in the output file like : ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ Are these windows characters? how can i get rid of this? Much appreciated. Paul (1 Reply)
Discussion started by: Paul Moghadam
1 Replies

3. Shell Programming and Scripting

Strange behaviour of arrays in awk

Imagine 2 files f1 f2: file1_l1_c1 code_to_find file1_l1_c3 file1_l2_c1 file1_code2 file1_l2_c3 file1_l3_c1 file1_code3 file1_l3_c3 file2_l1_c1 file2_l1_c2 code_to_find file2_l2_c1 file2_l2_c2 file2_code5 file2_l3_c1 file2_l3_c2 file2_code3 Say we want to print lines from f2 having... (5 Replies)
Discussion started by: ripat
5 Replies

4. Hardware

Strange Characters from ILOM

Hello, I have an x86 server with an ILOM connection that produces strange characters when I perform a start /SP/console, see below: Oracle(R) Integrated Lights Out Manager Version 3.0.16.10.a r68533 Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. -> start... (9 Replies)
Discussion started by: kerrygold
9 Replies

5. Red Hat

Spanish Characters get converted in strange chrac

I am trying to sftp a textfile from windows to linux. The file includes some spanish characters. When I vi the file in LINUX, the special (spanish) characters get converted into some strange characters. anyone know how i can resolve this? for example México gets converted into México on LINUX. (0 Replies)
Discussion started by: mrx1350
0 Replies

6. Shell Programming and Scripting

Grep a file that may contain strange characters

Hello unix users :) I am trying to grep a string from a file that both the file and the string may have characters in them that are quite... strange, like würzburger. Well, bash reads this as W%C3%BCrzburger For example, if i do wget W%C3%BCrzburger the output is: --2012-01-08... (2 Replies)
Discussion started by: hakermania
2 Replies

7. Shell Programming and Scripting

Strange Characters After Using Notepad

Hello all, I'm new to UNIX and new to this forum, so forgive my lack of knowledge. I'm new with editing in vi so I FTP scripts to a Windows machine and edit the script in notepad (when I need to do something quickly). Sometimes when I FTP the script back to the UNIX box, strange characters... (4 Replies)
Discussion started by: dgower2
4 Replies

8. Shell Programming and Scripting

Lines with strange characters and sed...

Dear All: I Have a bunch of files which I'd like to process with a shell script. The problem is that the files have strange characters in their headers, like �g�8@L-000-MSG2__-ABCD________-FIRA_____-000001___-200806181330-__ ��e� Data from BLABLABLA, Instrument: BLABLA, Date:... (4 Replies)
Discussion started by: luiscarvalheiro
4 Replies

9. Shell Programming and Scripting

i want to combine two awk scripts which is having same loop and filelist

hi, to all give me some idea below scripts file=`cat filelist` for filename in $file do awk '{ if ($0 ~ /system/ && flag == 0) { flag=1; print $0; } else if ($0 ~ /system/ && flag == 1) { printf("%s SYSLAY %s %s %s\n",$1,$3, $4, $5); } else print $0; }' $filename >... (6 Replies)
Discussion started by: LAKSHMI NARAYAN
6 Replies

10. UNIX for Dummies Questions & Answers

Strange Characters in Filename

Hi folks. None of the conventional methods are working for my dilemma: I have a file in my root directory that has a name comprised of strange characters. When I do an ls, it just hangs at that file until I do a Cntrl-C. rm ./filename & rm \filename do not work. I am entering the... (4 Replies)
Discussion started by: kristy
4 Replies
Login or Register to Ask a Question