Find the answer to your Linux question:
Results 1 to 2 of 2
Can someone help me write a script that would filter out contents of a text file than save it? Here is a portion of my text file called 'fsd.txt' i ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Location
    Iowa
    Posts
    4

    Filter a text file

    Can someone help me write a script that would filter out contents of a text file than save it? Here is a portion of my text file called 'fsd.txt' i want to filter....

    Feature[ id=0 , geom=POLYGON ((-93.23087173555291 45.027015173947376, -93.23529330143086 45.031134906254515, -93.22526966748222 45.03663921971941, -93.22071442799766 45.032394248858154, -93.23087173555291 45.027015173947376)) , value=0.0 , colorIndex=8 ]

    what i want to do is filter out everything and just keep one set of lat/lon & the value so something like this, -93.23087173555291 45.027015173947376 value=0

    is there any way to do this and run a script? hope this made sense as i'm new to linux...thanks!

  2. #2
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Welcome to the forums!

    What you want is perfectly possible, but you do need to be able to predict where the info you want is... either by place, relation or pattern.

    For example:
    Every line with the word POLYGON has the data behind the second '(' in what are basically two space separated columns.

    You may want to read up on:
    cat, grep, cut, sed, awk, which ship with all distro's. You might also be interested in Perl.


    Saving output to a file is as easy as redirecting output. A quick&easy example:

    Code:
    cat file | grep pattern
    outputs all lines containing pattern

    Code:
    cat file | grep pattern > newfile
    stores all lines containing pattern in newfile (overwrites all data in newfile if any)

    Code:
    cat file | grep pattern >> newfile
    appends all lines containing pattern in newfile below the existing data, if any


    ___
    You could also be more direct
    Code:
    grep pattern file >> newfile
    but I feel that tends to get confusing if you add multiple layers of variables and filters.
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...