我有這個腳本,我想在執行條件之前列印一個標題 if
我的代碼
#!/usr/bin/awk -f
{for(i=13; i<=NF; i )
{if($i~"terror" || $i~ "Terror") print $0,i}
}
{for(i=13; i<=NF; i )
{if ($i ~ "bird" || $i~ "pigeon") print $0,i}
}
我的 csv
這是我的 CSV 的第一行。
Date,"Time","Location","Operator","Flight","Route","Type","Registration","cn/In",Aboard,Fatalities,Ground,"Summary"
04/11/1955,"17:30","Off Great Natuna Island, Sarawak","Air India","","Hong Kong - Jakarta","Lockheed 749A Constellation","VT-DEP","2666",19,19,0,"An explosion occurred at 18,000 feet while over the China Sea. A resulting fire which started on the starboard wing soon spread and eventually led to total hydrauliand electrical failure. Smoke filled the cockpit and the plane crashed. An act of political terrorism. An aircraft worker placed an incendiary device in the starboard wheel well." 53
10/04/1960,"17:40","Boston, Massachusett","Eastern Air Lines","375","Boston - Philadelphia","Lockheed 188A Electra","N5533","1062",72,62,0,"A few seconds after becoming airborne, the aircraft struck a flock of starlings. A number of these birds were ingested in engines No. 1, 2, and 4. Engine No. 1 was shut down and its propeller was feathered. Engines No. 2 and 4 experienced a substantial momentary loss of power. This abrupt and intermittent loss and recovery of power resulted in the aircraft yawing to the left and decelerating to the stall speed. As speed decayed during the continued yaw and skidding left turn, the stall speed was reached; the left wing dropped, the nose pitched up, and the aircraft rolled left into a spin and fell almost vertically into the water. An altitude of less than 150 feet precluded recovery." 25
03/24/1968,"10:59","Off Wexford Harbor, Ireland","Aer Lingus","712","Cork - London","Vickers Viscount 803","EI-AOM","178",61,61,0,"The aircraft was believed to have gone into a spin or spiral dive with recovery at about 12,000 ft. The dive apparently caused structural damage which resulted in the aircraft plunging into St George's Channel, 10 miles east of Carnsore Point. Possible causal factors may have been metal fatigue, corrosion, flutter (vibration) or a bird strike." 63
12/21/1988,"19:03","Lockerbie, Scotland","Pan American World Airways","103","London - New York City","Boeing B-747-121A","N739PA","19646/15",259,259,11,"The airliner disappeared from radar shortly after leveling off at FL 310 while on a flight from Heathrow Airport, London, to New York. The aircraft broke up with two main sections of wreckage coming down in the town of Lockerbie. Detonation of an explosive device in the forward cargo area planted by terrorists. Musician Paul Jeffreys killed. The aircraft was named 'Clipper Maid of the Seas.'" 62
輸入我有
./c_awk.awk DataAirpleneCrashes.csv
我有的輸出
04/11/1955,"17:30","Off Great Natuna Island, Sarawak","Air India","","Hong Kong - Jakarta","Lockheed 749A Constellation","VT-DEP","2666",19,19,0,"An explosion occurred at 18,000 feet while over the China Sea. A resulting fire which started on the starboard wing soon spread and eventually led to total hydrauliand electrical failure. Smoke filled the cockpit and the plane crashed. An act of political terrorism. An aircraft worker placed an incendiary device in the starboard wheel well." 53
10/04/1960,"17:40","Boston, Massachusett","Eastern Air Lines","375","Boston - Philadelphia","Lockheed 188A Electra","N5533","1062",72,62,0,"A few seconds after becoming airborne, the aircraft struck a flock of starlings. A number of these birds were ingested in engines No. 1, 2, and 4. Engine No. 1 was shut down and its propeller was feathered. Engines No. 2 and 4 experienced a substantial momentary loss of power. This abrupt and intermittent loss and recovery of power resulted in the aircraft yawing to the left and decelerating to the stall speed. As speed decayed during the continued yaw and skidding left turn, the stall speed was reached; the left wing dropped, the nose pitched up, and the aircraft rolled left into a spin and fell almost vertically into the water. An altitude of less than 150 feet precluded recovery." 25
03/24/1968,"10:59","Off Wexford Harbor, Ireland","Aer Lingus","712","Cork - London","Vickers Viscount 803","EI-AOM","178",61,61,0,"The aircraft was believed to have gone into a spin or spiral dive with recovery at about 12,000 ft. The dive apparently caused structural damage which resulted in the aircraft plunging into St George's Channel, 10 miles east of Carnsore Point. Possible causal factors may have been metal fatigue, corrosion, flutter (vibration) or a bird strike." 63
12/21/1988,"19:03","Lockerbie, Scotland","Pan American World Airways","103","London - New York City","Boeing B-747-121A","N739PA","19646/15",259,259,11,"The airliner disappeared from radar shortly after leveling off at FL 310 while on a flight from Heathrow Airport, London, to New York. The aircraft broke up with two main sections of wreckage coming down in the town of Lockerbie. Detonation of an explosive device in the forward cargo area planted by terrorists. Musician Paul Jeffreys killed. The aircraft was named 'Clipper Maid of the Seas.'" 62
我想要的輸出
***** Terrorism accidents *******
04/11/1955,"17:30","Off Great Natuna Island, Sarawak","Air India","","Hong Kong - Jakarta","Lockheed 749A Constellation","VT-DEP","2666",19,19,0,"An explosion occurred at 18,000 feet while over the China Sea. A resulting fire which started on the starboard wing soon spread and eventually led to total hydrauliand electrical failure. Smoke filled the cockpit and the plane crashed. An act of political terrorism. An aircraft worker placed an incendiary device in the starboard wheel well." 53
12/21/1988,"19:03","Lockerbie, Scotland","Pan American World Airways","103","London - New York City","Boeing B-747-121A","N739PA","19646/15",259,259,11,"The airliner disappeared from radar shortly after leveling off at FL 310 while on a flight from Heathrow Airport, London, to New York. The aircraft broke up with two main sections of wreckage coming down in the town of Lockerbie. Detonation of an explosive device in the forward cargo area planted by terrorists. Musician Paul Jeffreys killed. The aircraft was named 'Clipper Maid of the Seas.'" 62
********Bird accidents********
10/04/1960,"17:40","Boston, Massachusett","Eastern Air Lines","375","Boston - Philadelphia","Lockheed 188A Electra","N5533","1062",72,62,0,"A few seconds after becoming airborne, the aircraft struck a flock of starlings. A number of these birds were ingested in engines No. 1, 2, and 4. Engine No. 1 was shut down and its propeller was feathered. Engines No. 2 and 4 experienced a substantial momentary loss of power. This abrupt and intermittent loss and recovery of power resulted in the aircraft yawing to the left and decelerating to the stall speed. As speed decayed during the continued yaw and skidding left turn, the stall speed was reached; the left wing dropped, the nose pitched up, and the aircraft rolled left into a spin and fell almost vertically into the water. An altitude of less than 150 feet precluded recovery." 25
03/24/1968,"10:59","Off Wexford Harbor, Ireland","Aer Lingus","712","Cork - London","Vickers Viscount 803","EI-AOM","178",61,61,0,"The aircraft was believed to have gone into a spin or spiral dive with recovery at about 12,000 ft. The dive apparently caused structural damage which resulted in the aircraft plunging into St George's Channel, 10 miles east of Carnsore Point. Possible causal factors may have been metal fatigue, corrosion, flutter (vibration) or a bird strike." 63
uj5u.com熱心網友回復:
由于沒有輸入示例,我使用您的“我擁有的輸出”作為輸入。
我還檢查了整行是否包含單詞恐怖或鳥,但如果您需要它所在的列,您可以更改它。
cat testInput | awk '{ if(toupper($0) ~ /TERROR/) { varTerror=varTerror"\n"$0; next; } if(toupper($0) ~ /BIRD/) {varBird=varBird"\n"$0; next; } } END { if(varTerror != "") { print " ***** Terrorism accidents ******* "; print varTerror } if(varBird != "") { print " ******** Bird accidents ******** "; print varBird } }'
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/399157.html
