Results 1 to 3 of 3
Code:
#!/bin/bash
touch xrandr
xrandr -q > xrandr #place xrandr in file, works
for (( VAR=0 ; ; VAR++ ))
do
TMP=$(cat xrandr | awk 'NR==$VAR { printf $2 }') ...
- 07-24-2010 #1Just Joined!
- Join Date
- May 2010
- Posts
- 8
Reading file (output from xrandr -q)
I'm trying to make several files: each named after the display and containing resolutions. But for some reason I get null when trying to read lines. Also, I'm noob.Code:#!/bin/bash touch xrandr xrandr -q > xrandr #place xrandr in file, works for (( VAR=0 ; ; VAR++ )) do TMP=$(cat xrandr | awk 'NR==$VAR { printf $2 }') #null? TMP1=$(cat xrandr | awk 'NR==$VAR { printf $1 }') #null? if [ "$TMP"=="" ]; then break #EOF elif [ "$TMP"~="connected" ]; then #new display rm $TMP1 #remove previous file touch $TMP1 TMP2=$TMP1 #set path for storing resolutions elif [ "$TMP2"!="" ]; then echo "$TMP1 " >> $TMP2 fi done
- 07-24-2010 #2
The problem has to do with your awk scripts.
Although you have defined a variable called VAR, this variable is a Bash variable, not an awk variable. Therefore, in your awk script, it looks for the varaible VAR, sees that it doesn't exist, and treats $VAR as $0, which isn't what you want.
You can do something like:
This way, you have defined the awk VAR variable to be the same as the Bash $VAR variable.Code:TMP=$(cat xrandr | awk -v "VAR=$VAR" 'NR==VAR { printf $2 }')DISTRO=Arch
Registered Linux User #388732
- 07-25-2010 #3Just Joined!
- Join Date
- May 2010
- Posts
- 8
Code:CONNECTED=$(cat xrandr | awk -v "VAR=$VAR" 'NR==VAR { printf $2 }')What I'm missing? (tested with single quotes as well)Code:cat: No such file or directory


Reply With Quote