The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Questions about Unix/Linux Vallzi What's on Your Mind? 5 01-22-2007 10:09 AM
pulling scripts from unix to linux pjconfig UNIX for Dummies Questions & Answers 3 12-21-2005 02:10 PM
Absolute n00b questions about Unix / Linux CodeHunter UNIX for Dummies Questions & Answers 2 02-24-2005 05:46 AM
UNIX/Linux for Windows? and a few other questions... CornNuts Windows & DOS: Issues & Discussions 8 04-10-2002 01:45 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-01-2007
Registered User
 

Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Unix/Linux Scripts questions

Hi All,

You have a very large file, named 'ColCheckMe', tab-delimited, that you are asked to process. You are told that each line in 'ColCheckMe' has 7 columns, and that the values in the 5th column are integers. Using shell functions (and standard LINUX/UNIX filters), indicate how you would verify that these conditions were satisfied in 'ColCheckMe'

In the same file, you are told that each value in column 1 is unique. How would you verify that?


Write a shell function that counts the number of occurrences of the word “SpecStr” in the file 'ColCheckMe'.

Please advice.

Thanks much.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-01-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Homework? (rule 6)
Reply With Quote
  #3 (permalink)  
Old 10-02-2007
Registered User
 

Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Hello,

This is not homework or school work. I'm a seasoned C++ developer on windows. My current project is both, windows and unix based. As part of my expanding job duties, I'm getting my feet wet in the unix world as well.

My problem is that I have a very large file called ColCheckMe which is tab-delimited, that I have to process. Each line in ColCheckMe has 7 columns, and the values in the 5th column are integers. Using shell functions (and standard LINUX/UNIX filters), I have to verify that these conditions are satisfied in ColCheckMe. In the same file, each value in column 1 is unique. How do I verify that? I have to write a shell function that counts the number of occurrences of the word “SpecStr” in the file ColCheckMe.

Thanks for any help.
Reply With Quote
  #4 (permalink)  
Old 10-02-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,983
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
nawk 'NF != 7 {printf("[%d] has invalid [%d] number of fields\n", FNR, NF)} $5 !~ /^[0-9]+$/ {printf("[%d] 5th field is invalid [%s]\n", FNR, $5)}' ColCheckMe

The rest is left as an excersize....
Reply With Quote
  #5 (permalink)  
Old 10-02-2007
Registered User
 

Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
what does it accomplish
Reply With Quote
  #6 (permalink)  
Old 10-03-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,983
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by am2007 View Post
what does it accomplish
it:
  1. checks for the valid number of fields
  2. checks for the 5-th field being integer field
Being 'seasoned C++' developer I'm sure you could've at least guessed OR at most tried it and saw the results....
Reply With Quote
  #7 (permalink)  
Old 10-03-2007
Registered User
 

Join Date: Oct 2007
Posts: 4
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Well, first off, it's a shame if you write code (that too, all in one executable line) that only you can understand....no need for the brickbats though. If you don't like to help without throwing insults, then don't help at all.
Reply With Quote
  #8 (permalink)  
Old 10-03-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,983
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
let me simplify it for you:
Code:
nawk '
    NF != 7 {
        printf("[%d] has invalid [%d] number of fields\n", FNR, NF)
    }
    $5 !~ /^[0-9]+$/ {
        printf("[%d] 5th field is invalid [%s]\n", FNR, $5)
}' ColCheckMe
Is it somewhat easier to parse/understand?
You should be able to see some of the familiar C/C++ concepts.

As far as helping others... I'm always willing to go 'extra mile' for someone who's willing to take a ride with me investing his/her/its own time investigating the "hints" given.
Having said that.... I'll close the 'brickbats' discussion.
Reply With Quote
Google UNIX.COM
Reply

Tags
linux

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix export command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script rsync ftp scp recursive segmentation fault(coredump) sftp script snoop unix solaris change ip address stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix mtime unix simulator unix.com vi substitute while loop within while loop shell script


All times are GMT -7. The time now is 03:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101