Search Results

Search: Posts Made By: andylbh
Forum: Programming 01-15-2011
7,104
Posted By rthomps7
bool login() { string user[10],password[10],...
bool login()
{
string user[10],password[10], user1, password1;
ifstream myfile("idpw.txt");

cout << "Please enter your username" << endl;
cin >> user1;
cout << "Please enter your...
2,788
Posted By Franklin52
printf "%0.2f" $price Prints a value in 2...
printf "%0.2f" $price

Prints a value in 2 decimal places.
12,862
Posted By ctsgnb
grep -i 'Supermarket B' infile.txt | sed 's/:/,...
grep -i 'Supermarket B' infile.txt | sed 's/:/, /;s/:/, \$/'

# cat infile2
Chocolate:Supermarket A:5
Ice Cream:SuperMarket B:7
Banana:Supermarket B:3
# grep -i 'Supermarket B' infile2 | sed...
12,862
Posted By Franklin52
awk -F: '/Supermarket B/{$3="$"$3;print}' OFS=\,...
awk -F: '/Supermarket B/{$3="$"$3;print}' OFS=\, file | sed 's/,/, /g'
13,853
Posted By Scott
Pattern|Action|Meaning /^Chocolate/|{$4=5}|For...
Pattern|Action|Meaning
/^Chocolate/|{$4=5}|For a line starting with "Chocolate", set the fourth field to "5"
1|-|1 evaluates to true. If no action is specified the default action is to print the...
13,853
Posted By Scrutinizer
It means on the line starting with Chocolate...
It means on the line starting with Chocolate replace the first occurrence of the pattern with 5. The pattern is [^:]*, which means 0 or more occurrences (*) of any character that isn't ":"

---...
13,853
Posted By michaelrozar17
:b: sed '/^Chocolate/{/:/s/12/5/4}' inputfile >...
:b:
sed '/^Chocolate/{/:/s/12/5/4}' inputfile > outfile
Change the last number (here) 4, according to the position of 12 you want to change
13,853
Posted By Scott
You're right. I never remember that thing :D
You're right. I never remember that thing :D
13,853
Posted By Scrutinizer
Not that ugly :) sed '/^Chocolate/s/[^:]*/5/5'...
Not that ugly :)
sed '/^Chocolate/s/[^:]*/5/5' file
(4th 12 is the fifth field, right?)
13,853
Posted By Scott
Well, I never saw that question coming ;) :D ...
Well, I never saw that question coming ;) :D

sed starts getting ugly when you try to do this stuff.


$ awk -F: '/^Chocolate/ {$4=5}1' OFS=: file1
Chocolate:12:12:5:12:12:12:12
13,853
Posted By anurag.singh
Depending on how exactly you want to edit: If...
Depending on how exactly you want to edit:
If you want to change all line having "Chocolate:5:5" to "Chocolate:5:10"

sed 's/Chocolate:5:5/Chocolate:5:10/'


OR change all lines "Banana:33:3"...
13,853
Posted By Scott
$ cat file1 (Product:Price:QuantityAvailable)...
$ cat file1
(Product:Price:QuantityAvailable) (: as delimiter)
Chocolate:5:5
Banana:33:3

$ sed "/^Chocolate/ s/[^:]*$/14/" file1
(Product:Price:QuantityAvailable) (: as delimiter)...
1,856
Posted By Scrutinizer
Yes, in the case of bash use the second option...
Yes, in the case of bash use the second option...
1,856
Posted By Scrutinizer
You're welcome! If you have ksh93 (which is the...
You're welcome! If you have ksh93 (which is the only shell with floating point arithmetic) use:
totalsales=$((price * qtysold))otherwise:
totalsales=$(echo "$price * $qtysold" | bc)
1,856
Posted By Scrutinizer
Try printf: awk -F: '{printf "%-25s %-6s %3d...
Try printf:
awk -F: '{printf "%-25s %-6s %3d %s\n",$1,$2,$3,$4}' infile
while IFS=: read name age gender country
do
printf "%-25s %-6s %3d %s\n" "$name" "$age" "$gender" "$country"
done <...
Showing results 1 to 15 of 15

 
All times are GMT -4. The time now is 10:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy