![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a file line by line | VENC22 | UNIX for Dummies Questions & Answers | 4 | 10-30-2008 11:09 AM |
| Read value from particular position in file. | krishnarao | Shell Programming and Scripting | 2 | 05-15-2008 07:49 AM |
| read space filled file and replace text at specific position | COD | Shell Programming and Scripting | 6 | 04-21-2008 06:40 AM |
| read or search the item in a file sequentially by position using unix shell script? | lok | UNIX for Dummies Questions & Answers | 6 | 07-12-2006 07:53 AM |
| How to read from a file line by line and do stuff | spaceship | Shell Programming and Scripting | 4 | 03-17-2005 09:47 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read file until certain line position
let's say I have this file format
Quote:
Quote:
Last edited by finalight; 05-21-2008 at 04:22 AM.. |
|
||||
|
If you grab the values between the separators into a variable then echoing that variable without quoting it will "magically" condense the whitespace into one space per run of whitespace. That doesn't work too well if the input is supposed to contain the asterisk, though, because that will be expanded as a wildcard. Instead, you can use tr to change newlines to spaces: Code:
variable1=`sed -n '/^test$/,/^\*\*$/p file1 | tr '\012' ' '` variable2=`sed -n '/^test$/,/^\*$/p' file2 | tr '\012' ' '` Your example had two asterisks at the end in the first file; if that was an error, change the first line. If your tr doesn't understand '\012' to mean newline, see its manual page, or search these forums for a solution; it has been posted multiple times, but there are too many different variations to summarize here. |
|
|||||
|
Here is one way of doing what you want to do - but requires ksh93 Code:
#!/bin/ksh93 # # showme # TMP=file.$$ cat <<'EOT' >$TMP first test dfgsdgs sdgsg 3 4 sd 6 sdgsdg 8 9 ** last EOT # read required lines into var var=$( exec 3< $TMP 3<#'test' 3<# ((CUR + 5)) 3<##'\*\**' exec 3<&- ) rm $TMP # remove newlines tmp=$(print $var) print "var: $tmp" exit 0 the output is Code:
$ ./showme dfgsdgs sdgsg 3 4 sd 6 sdgsdg 8 9 $ Last edited by fpmurphy; 05-20-2008 at 09:25 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|